![](/img/trans.png)
[英]How Do I Graph 1000 Points Onto A Graph, With Different Points Being Different Colors?
[英]I have 7 different data points for virus concentration collected at 3 different time points. How do I graph this with error bars in R?
我收集了七個不同的樣本,其中包含不同濃度的昆津病毒。
如何創建反映此數據的點圖,包括 R 中的誤差條? 我正在使用 ggplot2。
到目前為止我的代碼是:
data1 <-data.frame(hours, titer)
ggplot(data1, aes(x=hours, y=titer, colour = hours)) + geom_point()
我建議你下一個方法。 如果你想要誤差線,你可以根據均值和標准差來計算它。 在下一個代碼中勾畫了這樣做的方法。 我使用了一個標准偏差,但您可以設置任何其他值。 另外,由於您想查看不同的示例,我使用了facet_wrap()
。 這里的代碼:
library(ggplot2)
library(dplyr)
#Data
df <- data.frame(sample=c(rep('24 hour',3),rep('48 hour',2),rep('72 hour',2)),
titer=c(667, 1330, 1670,323000, 590000,3430000, 4670000),
stringsAsFactors = F)
#Compute error bars
df <- df %>% group_by(sample) %>% mutate(Mean=mean(titer),SD=sd(titer))
#Plot
ggplot(df,aes(x=sample,y=titer,color=sample,group=sample))+
geom_errorbar(aes(ymin=Mean-SD,ymax=Mean+SD),color='black')+
geom_point()+
scale_y_continuous(labels = scales::comma)+
facet_wrap(.~sample,scales='free')
輸出:
如果你有一個通用的 y 軸刻度,你可以試試這個:
#Plot 2
ggplot(df,aes(x=sample,y=titer,color=sample,group=sample))+
geom_errorbar(aes(ymin=Mean-SD,ymax=Mean+SD),color='black')+
geom_point()+
scale_y_continuous(labels = scales::comma)+
facet_wrap(.~sample,scales = 'free_x')
輸出:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.