我想用 1 个 geom_point 和 2 个 geom_line 创建一个 ggplot(根据我的变量计算,该变量将在我的 geom_point 上表示)
这是我认为正确的脚本,但我无法让 2 geom_line 出现在我的 ggplot 上。但是,当我在 geom_point 中更改它们时,它们都正确显示在图表上,请参见底部的图像。
#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")
感谢您的帮助