我了解,为了更改x轴的角度,我们应该使用theme() and axis.text.x=element_text(size=1, angle=90)
对于绘图,我使用geom_col
,因为我的x轴不是连续变量,而是类别。谁能让我知道我做错了还是错过了?对于R
和ggplot
精明的用户来说,某些东西必须显而易见!谢谢!
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") +
theme(axis.text.x=element_text(size=1, angle=45)) +
geom_hline(yintercept=0.2, linetype="dashed", color = "red") +
ggtitle("test") +
theme_bw()