如何用注释在ggplot2中绘制箭头 [英] how to draw arrow in ggplot2 with annotation
本文介绍了如何用注释在ggplot2中绘制箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个ggplot图表,我需要添加一些注释。我可以做到这一点,但文字并不完全指向我喜欢注释的日期。有没有一种方法可以绘制箭头到axix,我喜欢创建注释。
I am creating a ggplot chart where I need to put some annotation. I can do that but the text is not really pointing exactly the date that I like annotate. Is there a way to draw an arrow to axix where I like create the annotation.
我有这个:
I have this:
ggplot(df, aes(Date, CPU)) + geom_point() +
annotate("text", x = as.POSIXct(c("2013-03-11 23:00:00")),
y = 90, label = "problem 1", angle=90, size=5,
colour='black', face="bold")
推荐答案
正因如此,任何人都可能有相同的问题或查询,下面是我做了:
just so anyone might have the same question or query, here is what I did:
library(ggplot2)
library(grid)
ggplot(df, aes(Date, CPU)) + geom_point() +
annotate("text", x = as.POSIXct(c("2013-03-11 23:00:00")),
y = 90, label = "problem 1", angle=90, size=5,
colour='black', face="bold")
+ geom_segment(aes(x = as.POSIXct(c("2013-03-11 09:00:00")), y = -30, xend = as.POSIXct(c("2013-03-11 09:00:00")), yend = 0), colour='#CC00FF', size=1,arrow = arrow(length = unit(0.5, "cm")))
这篇关于如何用注释在ggplot2中绘制箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文