我有一个这样的数据框
PDATETIME <- c("2017-02-23 06:08:39","2017-02-25 15:31:50","2017-03-06 17:11:57","2017-03-15 01:23:51",
"2017-03-16 15:54:35","2017-03-16 23:48:14","2017-03-18 02:57:41","2017-03-20 05:12:33")
DELTA <- c(2.5,8,3.5,4.5,5.5,8.3,3.3,4)
Type <- c(NA,"Outlier",NA,NA,NA,"Outlier",NA,NA)
df <- data.frame(PDATETIME,DELTA,Type)
df$PDATETIME <- as.POSIXct(df$PDATETIME,format="%Y-%m-%d %H:%M:%S")
我正在尝试使用ggplot2在离群点绘制垂直线
library(ggplot2)
library(ggrepel)
ggplot(data = df, aes(PDATETIME,DELTA ))+
ggtitle("Outlier Analysis") +
theme(axis.text.x = element_text(angle=90, vjust=1),plot.title = element_text(size = rel(1))) +
geom_point(colour="black") +
geom_vline(aes(xintercept=df$PDATETIME[which(df$Type %in% "Outlier")],linetype=4, colour="black")) +
geom_text_repel(aes(PDATETIME, DELTA,
label = Type),
size =4,
fontface = 'bold',
color = 'red',
box.padding = 0.5,
point.padding = 0.5,
segment.color = 'darkblue',
segment.size = 0.5,
arrow = arrow(length = unit(0.01, 'npc'))) +
xlab("PDATETIME")+
ylab("DELTA")
引发错误“ Error: A continuous variable can not be mapped to linetype
”
离群点位于2017-02-25 15:31:50、2017-03-16 23:48:14
我在这里想念什么?有人可以指出我正确的方向吗?
linetype
并且color
没有变化,因此您可以将它移到外面aes
。另外,我建议您将代码修改为:
geom_vline(data = df[which(df$Type %in% "Outlier"),],
aes(xintercept = PDATETIME),
linetype = 4, colour = "black")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句