Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

r - 合并来自两个不同数据帧的两个折线图(Combining two line plots from different two data frames)

I have two line graphs showing: one showing the decline of six species over the four sampling and the other showing the total decline of the same six species.

(我有两个折线图显示:一个显示四个采样中六个物种的下降,另一个显示相同六个物种的总下降。)

I want to create a plot that has the six species shown individually and the total decline.

(我想创建一个图,该图具有单独显示的六个物种和总衰落。)

Below is an example of my data frame for the six species

(以下是我对这六个物种的数据框的示例)

 Week       Species      Unit
   1           A           13
   1           B           24
   2           B           15
   2           C           32
   3           C           43
   4           D           32

Below is the code I have used to create the line graph showing the decline of the six species

(以下是我用来创建折线图的代码,用于显示六种物种的衰落)

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")

Below is a sample of the data frame showing the total count of all species over the sampling period

(以下是数据框的示例,显示了整个采样期内所有物种的总数)

Week           Unit
 1              32
 2              55
 3              73
 4              62

Below shows the code used to create the second line graph showing the total count of all species over the sampling rounds

(下面显示了用于创建第二个折线图的代码,该折线图显示了采样回合中所有物种的总数)

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")
  ask by niamhailbhe translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure if this is what you want but you can add a new species called "total" to your Total_count data.frame .

(我不确定这是否是您想要的,但是您可以在Total_count data.frame添加一个名为“ total”的新种类。)

Using the data you provided:

(使用您提供的数据:)

Data 数据)
 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)) 
Code 码)
 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 

绘图结果

Hope this helps!

(希望这可以帮助!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...