我想在垂直线的顶部添加文本,我添加到 ggplot 中的密度图;诸如“目标长度”之类的东西;似乎在任何地方都不是解决方案。
ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha = 0.5) +
geom_vline(xintercept = 6, linetype="dashed",
color = "black", size=1, )
Run Code Online (Sandbox Code Playgroud)
我希望在 geom_label 中有一个可能的框,但 geom_text 的一些变化也足够了。
将 annotate 与 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")
Run Code Online (Sandbox Code Playgroud)