是否可以在R中的ggplot2中左对齐X轴标签

问题描述 投票:0回答:1

如果这是重复的,我们深表歉意。我找不到它! :-)

我只是将 x 轴标签“cyl”变为左对齐。这当然是可能的。

示例(ggplot 包中的 mpg):

g <- ggplot(mpg, aes(factor(cyl), hwy))
g + geom_boxplot(varwidth=T, fill="plum") + 
  labs(title="Box plot", x="cyl",y="hwy")

一如既往地感谢。

r ggplot2 visualization
1个回答
1
投票

您可以通过

axis.title.x
设置对齐方式,如下所示:

library(ggplot2)

ggplot(mpg, aes(factor(cyl), hwy)) +
  geom_boxplot(varwidth = T, fill = "plum") +
  labs(title = "Box plot", x = "cyl", y = "hwy") +
  theme(axis.title.x = element_text(hjust = 0))

© www.soinside.com 2019 - 2024. All rights reserved.