我有几个 geom_bar ggplots,其中 x 轴文本的名称很长。如果我以角度 = 90 绘制它们,则图表底部会占用大量空间,因此我尝试角度 = 45。这会导致第一个标签的左侧被切断。有没有办法增加左边距?
(不允许发布图片示例)
ggplot(aes(x = cm, y = ahead_aadt),
data = sbt) +
geom_point( ) + geom_line() +
ggtitle("Ahead AADT Traffic Counts On US 101 in S Santa Barbara Cty") +
theme(axis.text.x = element_text(angle=45, size = 9,
color = "black", face = "plain", vjust = 1, hjust = 1),
panel.grid.major.x = element_line(colour = "black", linetype = "dotted")) +
xlab("Cumulative Mileage") + ylab("Ahead AADT") +
scale_x_continuous(breaks = sbt$cm,
labels = sbt$description)
对于您的问题会有更好的解决方案:只需点击链接即可用户3055034假如。调整plot.margin
与新的margin()
类似于我下面的例子。
library(ggplot2)
# long labels
labels <- c(paste(c(letters, letters), collapse = ""), "6", "8")
ggplot(mtcars, aes(as.factor(cyl), mpg)) +
geom_point() +
scale_x_discrete(labels = labels) +
theme(axis.text.x = element_text(angle = 45, size = 9,
color = "black", face = "plain", vjust = 1, hjust = 1),
plot.margin = margin(10, 10, 10, 100))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)