axis.text不改变角度

axis.text does not change angle

我知道为了改变 x 轴的角度我们应该使用 theme() and axis.text.x=element_text(size=1, angle=90)

对于绘图,我使用了 geom_col,因为我的 x 轴不是连续变量,只是类别。谁能让我知道我做错了什么或错过了什么?对于 Rggplot 精明的用户来说,有些事情必须是显而易见的!谢谢!

data("diamonds")
example_df <- diamonds[unique(diamonds$clarity), ]

ggplot(example_df, aes(reorder(clarity, -carat, sum), carat)) +
  geom_col() + 
  xlab("clarity")+
  ylab("carat") +
  theme(axis.text.x=element_text(size=1, angle=45)) +
  geom_hline(yintercept=0.2, linetype="dashed", color = "red") +
  ggtitle("test") +
  theme_bw()

最后调用 theme_bw() 会重置您之前添加的所有 theme 更改。只有最后一个值保留下来。只需更改设置值的顺序

ggplot(example_df, aes(reorder(clarity, -carat, sum), carat)) +
  geom_col() + 
  xlab("clarity")+
  ylab("carat") +
  geom_hline(yintercept=0.2, linetype="dashed", color = "red") +
  ggtitle("test") +
  theme_bw() + 
  theme(axis.text.x=element_text(size=1, angle=45))