axis.text不会改变角度

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

我了解,为了更改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()

enter image description here

r ggplot2 axis
1个回答
1
投票

最后调用theme_bw()会重置您先前添加的所有theme更改。只有最后一个值有效。只需更改设置值的顺序即可

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()
© www.soinside.com 2019 - 2024. All rights reserved.