我正在绘制一个图形,在x轴上有一个分类变量,在y轴上有一个数值变量。
对于x轴,如果有许多数据点,默认文本格式会导致每个刻度线的标签与其他标签重叠。如何(a)更改轴文本的字体大小和(b)更改文本的方向以使文本垂直于轴?
发布于 2012-11-09 05:30:25
使用theme()
d <- data.frame(x=gl(10, 1, 10, labels=paste("long text label ", letters[1:10])), y=rnorm(10))
ggplot(d, aes(x=x, y=y)) + geom_point() +
theme(text = element_text(size=20),
axis.text.x = element_text(angle=90, hjust=1))
#vjust adjust the vertical justification of the labels, which is often useful
这里有很多关于如何格式化here图的好信息。您可以看到可以使用?theme
修改(基本上是全部)的参数的完整列表。
发布于 2012-11-09 05:58:58
theme()
的用法同上@Drew Steen。以下是轴文本和标题的常见主题属性。
ggplot(mtcars, aes(x = factor(cyl), y = mpg))+
geom_point()+
theme(axis.text.x = element_text(color = "grey20", size = 20, angle = 90, hjust = .5, vjust = .5, face = "plain"),
axis.text.y = element_text(color = "grey20", size = 12, angle = 0, hjust = 1, vjust = 0, face = "plain"),
axis.title.x = element_text(color = "grey20", size = 12, angle = 0, hjust = .5, vjust = 0, face = "plain"),
axis.title.y = element_text(color = "grey20", size = 12, angle = 90, hjust = .5, vjust = .5, face = "plain"))
发布于 2014-09-21 08:13:48
使用主题():
d <- data.frame(x=gl(10, 1, 10, labels=paste("long text label ", letters[1:10])), y=rnorm(10))
ggplot(d, aes(x=x, y=y)) + geom_point() +
theme(text = element_text(size=20))
https://stackoverflow.com/questions/13297995
复制相似问题