我想在垂直线的顶部添加文本,我添加到 ggplot 中的密度图;诸如“目标长度”之类的东西;似乎在任何地方都不是解决方案。
ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha = 0.5) +
geom_vline(xintercept = 6, linetype="dashed",
color = "black", size=1, )
我更喜欢在 geom_label 中有一个可能的框,但 geom_text 的一些变化也足够了。
最佳答案
使用带有 geom="label"的注释?如果只有一个标签,那就更直接了,不会弄乱图例:
g = ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha = 0.5) +
geom_vline(xintercept = 6, linetype="dashed",
color = "black", size=1, )
g+annotate(x=6,y=+Inf,label="Target Length",vjust=2,geom="label")
关于r - 如何在ggplot中向geom_vline添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61701985/