R 如何在ggplot 2中绘制不同类别的时间序列数据

R 如何在ggplot 2中绘制不同类别的时间序列数据,r,ggplot2,time,R,Ggplot2,Time,这是数据集 group <- c(1,2,3,1,2,3) species <- c("rabbit","rabbit","rabbit","plant","plant","plant") t1 <- c(66,77,80,4,3,1) t2 <- c(4,5,22,1,2,6) t100 <- c(56,78,22,1,6,7) df <- data.frame(group, species,t1,t2,t100) 只需对df进行少量修改即可实现: 通过群

这是数据集

group <- c(1,2,3,1,2,3)
species <- c("rabbit","rabbit","rabbit","plant","plant","plant")
t1 <- c(66,77,80,4,3,1)
t2 <- c(4,5,22,1,2,6)
t100 <- c(56,78,22,1,6,7)
df <- data.frame(group, species,t1,t2,t100)

只需对df进行少量修改即可实现:

  • 通过
    群体
    物种

    图书馆(重塑) df2=熔体(df,id=c(“组”、“种”))

  • 列定义为系数:

  • df2$group=as.factor(df2$group)

    然后是情节:

    ggplot(df2, aes(x=variable, y=value, colour=group, shape = species, group=interaction(group, species))) + geom_point(size=3) + geom_line(size=1)
    

    ggplot(df2, aes(x=variable, y=value, colour=group, shape = species, group=interaction(group, species))) + geom_point(size=3) + geom_line(size=1)