ggplot2 – Trying to plot Graph in R with 3 variables

ggplot2 – Trying to plot Graph in R with 3 variables

Here is a reproducible example of your question, with a possible solution. Since you did not specify exactly what kind of plot you are looking for, I guessed you would like a line plot with 3 different colored lines.

DateTime = as.POSIXct(1/27/2017 6:49, format=%m/%d/%Y %H:%M) + 1:10*60
AMK = c(17,17,15,17,17,17,17,16,16,19)
SK = c(3,2,1,1,2,1,1,4,3,3)
JR = c(11,13,14,13,13,10,13,14,10,11)

df = data.frame(DateTime, AMK, SK, JR)

library(ggplot2)
library(dplyr)
library(tidyr)

dfplot <- df %>% gather(key, value, -DateTime)

ggplot(dfplot, mapping = aes(x = DateTime, y = value, color = key) ) + geom_line()

enter

ggplot2 – Trying to plot Graph in R with 3 variables

Leave a Reply

Your email address will not be published.