我知道为了改变 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()
Run Code Online (Sandbox Code Playgroud)
最后调用会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))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
222 次 |
| 最近记录: |