[英]ggplot vertical line with date axis
當x軸是datetime( POSIXct
)對象時,在向繪圖添加垂直線時遇到了一些麻煩。 似乎總是想把時間放在時代。 這是一個例子:
df <- data.frame(x=ymd('2011-01-01')+hours(0:24), y=runif(25))
ggplot(df, aes(x=x,y=y)) + geom_point()
現在,我嘗試在第三個觀察時間添加一行:
ggplot(df, aes(x=x,y=y)) + geom_point() + geom_vline(aes(x=df$x[3]))
我做錯了什么?
嘗試這樣做:
geom_vline(xintercept = df$x[3])
ggplot(df, aes(x=x,y=y)) + geom_point() + geom_vline(aes(xintercept=df$x[3]))
您需要在geom_vline
aes
xintercept
而不是x
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.