我是R的新手,我想创建一个带有连接线的"前后"散点图,以说明训练干预前后的不同功率输出。
我想要类似于图片中的图表的东西。
例
Sample Data
X <- c(0,1,0,1,0,1,0,1) # 0=before, 1=after
y <- c(1001,1030,900,950,1040,1020,1010,1000) #Power output
Group <- c(0,0,0,0,1,1,1,1) # 0=Control 1=Experimental
id <- c(1,1,2,2,3,3,4,4) # id = per individual
df <- data.frame(x,y,Group,id)
非常感谢
x <- c(0,1,0,1,0,1,0,1) # 0=before, 1=after
y <- c(1001,1030,900,950,1040,1020,1010,1000) #Power output
Group <- c(0,0,0,0,1,1,1,1) # 0=Control 1=Experimental
id <- c(1,1,2,2,3,3,4,4) # id = per individual
df <- dplyr::bind_cols(
x = x,
y = y,
Group = as.factor(Group),
id = as.factor(id)
)
library(ggplot2)
ggplot(df) +
aes(x,y, color = Group, shape = Group, group = id)+
geom_point()+
geom_line()