这个问题在这里已经有了答案:
ggplot2 plot area margins?
(1 个回答)
5年前关闭。
我有几个 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)
最佳答案
您的问题会有更好的解决方案:只需点击链接 user3055034假如。调整 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))
关于r - 如何操作 R 中的 ggplot 以在 lhs 上为角度 = 45 长 x 轴标签留出额外空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32918947/