如何操作facet_grid图的条带文本?
我想知道如何操纵分面图中条带文本的大小。我的问题 类似于 关于情节标题的问题,但我特别关心 操作的不是绘图标题,而是出现在分面标题 (strip_h) 中的文本。
例如,考虑 mpg 数据集。
library(ggplot2)
qplot(hwy, cty, data = mpg) + facet_grid( . ~ manufacturer)
生成的输出会生成一些不适合条带的分面标题。
我想一定有一种方法可以使用grid
来处理条带文本。但我是 还是个新手,从 Hadley 的 grid
附录中不确定预订如何, 准确地说,就是去做。
I'm wondering how I can manipulate the size of strip text in facetted plots. My question
is similar to a question on plot titles, but I'm specifically concerned with
manipulating not the plot title but the text that appears in facet titles (strip_h).
As an example, consider the mpg dataset.
library(ggplot2)
qplot(hwy, cty, data = mpg) + facet_grid( . ~ manufacturer)
The resulting output produces some facet titles that don't fit in the strip.
I'm thinking there must be a way to use grid
to deal with the strip text. But I'm
still a novice and wasn't sure from the grid
appendix in Hadley's book how,
precisely, to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
theme_text()
修改strip.text.x
(或strip.text.y
),例如更新:< /strong> ggplot2 版本 > 0.9.1
You can modify
strip.text.x
(orstrip.text.y
) usingtheme_text()
, for instanceUpdate: for ggplot2 version > 0.9.1
如今,
opts
和theme_text
的使用似乎已被弃用。 R 建议使用theme
和element_text
。可以在这里找到答案的解决方案: http:// /wiki.stdout.org/rcookbook/Graphs/Facets%20%28ggplot2%29/#modifying-facet-label-textNowadays the usage of
opts
andtheme_text
seems to be deprecated. R suggests to usetheme
andelement_text
. A solution to the answer can be found here: http://wiki.stdout.org/rcookbook/Graphs/Facets%20%28ggplot2%29/#modifying-facet-label-text我想在 mpg 的示例中,更改旋转角度和字体大小很好,但在许多情况下,您可能会发现自己的变量具有相当长的标签,这可能会成为一个令人头疼的问题(从字面上看)尝试读取旋转的冗长标签。
因此,除了(或补充)改变角度和大小之外,我通常会重新格式化定义
facet_grid
的因素的标签,只要它们可以以有意义的方式分割。通常,如果我有一个带有字符串的
dataset$variable
,看起来就像我所做的那样:
[也许有更好的
reformat
定义,但至少这个可以正常工作。]分面,所有标签都将非常可读:
I guess in the example of
mpg
changing the rotation angle and font size is fine, but in many cases you might find yourself with variables that have quite lengthy labels, and it can become a pain in the neck (literally) to try read rotated lengthy labels.So in addition (or complement) to changing angles and sizes, I usually reformat the labels of the factors that define the
facet_grid
whenever they can be split in a way that makes sense.Typically if I have a
dataset$variable
with strings that looks likeI simply do:
[perhaps there are better definitions of
reformat
but at least this one works fine.]And upon facetting, all labels will be very readable: