[英]Text and non-continuous line in a plot in r
I am trying to replicate this plot in R.我正在尝试在 R 中复制此 plot。
I have some difficulties: I don't know the code to create the line 90 min (it is not a continuous line, it starts at 2000)我有一些困难:我不知道创建线 90 分钟的代码(它不是连续线,它从 2000 开始)
How can I add the text R1, R2 and R3 in my plot?如何在我的 plot 中添加文本 R1、R2 和 R3?
How can I add the title for each line in my plot?如何在 plot 中为每一行添加标题?
This is my current code:这是我当前的代码:
plot(Year,Duration, abline(v=2000, col="green"))情节(年,持续时间,abline(v = 2000,col =“green”))
Thanks谢谢
Here's a stab at it, base graphics.这是一个尝试,基本图形。
set.seed(42)
dat <- data.frame(
Year = sample(1990:2040, size=100, replace=TRUE),
Duration = runif(n=100, min=-1, max=1)
)
plot(Duration ~ Year, data = dat, pch = 16, yaxt = 'n', xaxt = 'n', col = "orange")
abline(v = 2000, lwd = 2, col = "green4")
lines(c(2000, par("usr")[2]), rep(0, 2), lwd = 2, col = "green4")
text(c(1995, 2025, 2025), c(0, -0.5, 0.5), c("R1", "R2", "R3"))
mtext("90min", side = 4)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.