【发布时间】:2021-06-19 22:36:28
【问题描述】:
我正在尝试找到一种将 geom_text/geom_label 包装在散点图 (ggplot) 上的方法。我已经看到可以手动输入坐标的方法 - 但我将有 10-20 个变量,所以这是不可能的。
我有一个看起来像这样的数据框...
df <- data.frame(x =c(2,4,6,8),
y =c(7,3,5,4),
label =c("this variable has a long name which needs to be shortened",
"this variable has an even longer name that really needs to be shortened",
"this variables has a name that is much longer than two of the other name, so really needs to be shortened",
"this is pretty long too"))
我想制作以下情节(但带有包装标签)
ggplot(df, aes(x=x, y=y, label=label))+
geom_point()+
geom_text(nudge_y=0.05)+
xlim(0,10)+
theme_minimal()+
ggtitle("title")
剧情如下:
【问题讨论】: