I want to have multiple “lines” on the same plot. Multiple data points.
In my example, how can I include the ‘xa’ and ‘xb’ data points.
This is what I have for just one set of data points but I want two. How can I modify this script.
library(ggplot2)
da <- c("2012-02-02 09:01:00", "2012-02-02 09:02:00", "2012-02-02 09:03:00")
db <- c(0.4, 0.6, 0.5)
xa <- c("2012-02-02 09:01:00", "2012-02-02 09:02:00", "2012-02-02 09:03:00")
xb <- c(0.3, 0.43, 0.7)
da2 <- as.POSIXct(da)
dfx <- data.frame(da2, db)
summary(dfx)
png('time_data_errs6b.png', width=640, height=480)
gg <- qplot(da2, db, colour='red')+
opts(title = 'Requests App')+xlab('Time')+ylab('Requests') +
geom_line()
print(gg)
dev.off()
I would make two
data.framesandmergethem by the time variable.Convert to POSIXct like you did then melt it to a long format.
ggplot deals with long format data very well, so its usually my goal to get data into a suitable structure with
meltandmergebefore plotting.I also like to uses the base
ggplotrather thanqplotfor my own readability. but thats a matter of preference.