如何在ggplot2中旋转标签? [英] How can I rotate labels in ggplot2?
本文介绍了如何在ggplot2中旋转标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有标签的散点图.我想旋转标签-而不是水平位置,我想垂直查看它们.我只在Stackoverflow上看到关于旋转轴标签的q-s.
I have a scatter graph with lables. I want to rotate lables - instead of horizontal position I want to see them vertically. I only saw q-s about rotating axis lables on Stackoverflow.
示例:
mtdata <- mtcars %>%
rownames_to_column(var = "name")
ggplot(mtdata, aes(x = mpg, y = wt)) + geom_point() +
geom_label(data = mtdata %>%
filter(mpg > 20 & wt >3), aes(label = name))
推荐答案
如果可以使用 geom_text
,可以使用 angle
参数.
You can use angle
parameter if you are ok using geom_text
.
library(dplyr)
library(ggplot2)
ggplot(mtdata, aes(x = mpg, y = wt)) + geom_point() +
geom_text(data = mtdata %>% filter(mpg > 20 & wt >3),
aes(label = name), angle = 90, hjust = -1)
很遗憾, geom_label
中没有 angle
.
这篇关于如何在ggplot2中旋转标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文