[英]Plotting multiple line graphs in one using R
我有一個數據集,其中包含在3個不同實驗階段獲得的3000多種生物的讀取數。 數據看起來像這樣:
rain day0 day7
org1 923857 505062 503292
org2 424002 198440 26314
org3 2910 1492 535
...在此之后還有3000行
我想繪制每種生物在不同階段的趨勢(讀取數)..(開始,day0,day7)。 每種生物應以不同的顏色表示,並且所有生物都應在同一圖中。
我試過在excel中做同樣的事情,但在一個圖中只能有255條這樣的線。
有沒有辦法在R中做到這一點? 我是R的新手,因此了解的不多。 我認為ggplot可能有效,但是我很難理解如何在此數據上使用它。
任何幫助是極大的贊賞。 謝謝。
這是使用library(tidyverse)
的版本library(tidyverse)
我根據您提供的數據創建了一個data.frame,
gather
這些變量以將數據制成長格式,
更改了因子水平,使其與您提供的曲線對齊,
並使用ggplot
生成一個數字。
data.frame(org = letters[1:3],
rain = c(923857, 424002, 2910),
day0 = c(505062, 198440, 1492),
day7 = c(503292, 2614, 535)) %>%
gather(variable, value, -org) %>%
mutate(variable = factor(variable, levels = c('rain', 'day0', 'day7'))) %>%
ggplot(aes(variable, value, color = org, group = org)) +
geom_point() +
geom_line() +
theme(legend.position="bottom")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.