ggplot2 - Overlaying two/more graphs using R -
i have been referring stackoverflow posts , came query on gglot2 features.
the data set used code follows.
timestamp data_1 data_2 data_3 15:11:37.474 99.791028 0.312498 99.47853 15:16:22.373 99.791028 0.729162 99.061866 15:21:37.424 99.791028 0.104166 99.686862 15:31:52.475 88.02027 90.520254 15:42:07.157 99.99936 0.208332 99.791028 15:43:22.279 99.99936 0.52083 99.47853 15:45:37.673 99.686862 0 99.686862 15:52:52.872 99.686862 0.729162 98.9577 p1<- ggplot(df, aes(timestamp, data_1,group=1)) + geom_point() + geom_point(data = df[df$data_1 > 80,], pch = 21, fill = na, size = 4, colour = "red", stroke = 1) + geom_line() p2<-ggplot(df, aes(timestamp, data_3,group=1)) + geom_point() + geom_point(data = df[df$data_3 > 70,], pch = 21, fill = na, size = 4, colour = "blue", stroke = 1) + geom_line()
i trying overlay p1 , p2 same x , y axis using print(p1+p2).
but, came below error.
error in p + o : non-numeric argument binary operator in addition: warning message: incompatible methods ("+.gg", "ops.data.frame") "+"
what these graphs is; circle data points based on conditions , display 2 graphs in same region.
try
p1<- ggplot(df, aes(timestamp, data_1,group=1)) + geom_point(pch = 21, fill = na, size = 4, colour = "red", stroke = 1)+geom_point()+geom_line(colour = "red") p2 <- p1+geom_line(data=df, aes(timestamp, data_3),colour="blue")+ geom_point(data=df, aes(timestamp, data_3,group=data_3),colour="blue",pch = 21, size = 4, stroke = 1,fill= na)+geom_point(data=df, aes(timestamp, data_3,group=data_3)) print(p2)
Comments
Post a Comment