I want to create a ggplot with 1 geom_point and 2 geom_line (calculated from my variable that is going to be represented on my geom_point)
Here is the script that I though was correct, but I cannnot make the 2 geom_line to appear on my ggplot. However, when I change them in geom_point they all appear correctly on the graph see image at the bottom.
#Acute/chronique
library(dplyr)
library(ggplot2)
library(gsheet)
library(googlesheets)
library(tidyr)
date <- c("2014-07-06", "2014-07-07","2014-07-08","2014-07-09", "2014-07-09","2014-07-10","2014-07-11","2014-07-12","2014-07-13", "2014-07-14","2014-07-15","2014-07-16","2014-07-17")
par <- c("RPE", "RPE", "RPE", "RPE", "RPE", "RPE", "RPE", "RPE", "RPE", "RPE", "RPE", "RPE", "RPE")
temp <- c(14, 10, 16, 13, 10, 9, 10, 14, 16, 4, 7, 16, 18)
df <- data.frame(date, par, temp)
lag_functions <- setNames(c(paste("(", paste("dplyr::lag(., ", 1:3, ")", collapse = ' + '), ") / 3"),
paste("(", paste("dplyr::lag(., ", 1:5, ")", collapse = ' + '), ") / 5")),
c("acute", "chronic"))
ldf<-df%>%
mutate_at(vars(temp), funs_(lag_functions))
ldf
ggplot(ldf, aes(x = date, y = temp)) +
geom_point()
ggplot(ldf) +
geom_point(aes(x = date, y = temp)) +
geom_line(aes(x = date, y = acute), col = 'red') +
geom_line(aes(x = date, y = chronic), col = 'blue') +
xlab("Date") +
ylab("RPE")
Thank you for your help