R 从不同的两个数据帧组合两个线图

R 从不同的两个数据帧组合两个线图,r,ggplot2,linegraph,R,Ggplot2,Linegraph,我有两个折线图显示:一个显示在四次采样中六个物种的数量减少,另一个显示相同六个物种的数量减少。我想创建一个图,分别显示六个物种和总数量的下降 下面是我对这六个物种的数据框架示例 Week Species Unit 1 A 13 1 B 24 2 B 15 2 C 32 3

我有两个折线图显示:一个显示在四次采样中六个物种的数量减少,另一个显示相同六个物种的数量减少。我想创建一个图,分别显示六个物种和总数量的下降

下面是我对这六个物种的数据框架示例

 Week       Species      Unit
   1           A           13
   1           B           24
   2           B           15
   2           C           32
   3           C           43
   4           D           32
下面是我用来创建线条图的代码,它显示了这六个物种的衰退

Species_Change<-ggplot(Total_Count, aes(x=Week, y=Unit, group=Scientific.name, color=Scientific.name)) +
  geom_point()+
  geom_line()+
  scale_colour_manual(values = c("yellow", "orange 2", "purple", "maroon 2", "blue", "purple 4","green"))+
  ylab("Total number of floral units over the four habitats")+
  xlab("Sampling round")+
  labs(col="Plant species")
下面显示了用于创建第二个折线图的代码,该折线图显示了采样轮中所有物种的总数

Total_Change<-ggplot(Total_Round, aes(x=Week, y=Unit, )) +
  geom_point()+
  geom_line()+
  ylab("Total number of floral units over the four habitats")+
  xlab("Sampling round")+
  labs(col="Plant species")

Total\u Change我不确定这是否是您想要的,但您可以在
Total\u计数中添加一个名为“Total”的新物种。使用您提供的数据:

资料 代码
Total_Round$物种
Total_Change<-ggplot(Total_Round, aes(x=Week, y=Unit, )) +
  geom_point()+
  geom_line()+
  ylab("Total number of floral units over the four habitats")+
  xlab("Sampling round")+
  labs(col="Plant species")
dput(Total_Count)
structure(list(Week = c(1L, 1L, 2L, 2L, 3L, 4L), Species = structure(c(1L, 2L, 2L, 3L, 3L, 4L), .Label = c("A", "B", "C", "D"), class = "factor"), Unit = c(13L, 24L, 15L, 32L, 43L, 32L)), row.names = c(NA, -6L), class = "data.frame")
dput(Total_Round)
structure(list(Week = c(1, 2, 3, 4), Unit = c(32, 55, 73, 62)), class = "data.frame", row.names = c(NA, -4L))
Total_Round$Species <- factor(rep("Total",nrow(Total_Round))) # Create total species
df <- rbind(Total_Count, Total_Round) # Merge both data.frames
AllwithTotal_Species_Change<-ggplot(df, aes(x=Week, y=Unit, group=Species, color=Species)) +
  geom_point()+
  geom_line()+
  scale_colour_manual(values = c("yellow", "orange 2", 
                                 "purple", "maroon 2", 
                                 "blue", "purple 4",
                                 "green"))+
  ylab("Total number of floral units over the four habitats")+
  xlab("Sampling round")+
  labs(col="Plant species")
AllwithTotal_Species_Change