[英]how can i add points to geom_line plot in ggplot
我有一個如下的df,我想用geom_line生成時間序列圖。 以下是我的數據摘要:
summary(data.t.m)
sample side time day variable value
HA2015_E10AF.bam: 1 E:69 1 :12 F:72 nc.counts:138 Min. : 4.346
HA2015_E10BF.bam: 1 W:69 2 :12 S:66 1st Qu.: 6.949
HA2015_E10CF.bam: 1 3 :12 Median : 8.529
HA2015_E11AF.bam: 1 4 :12 Mean : 9.085
HA2015_E11AS.bam: 1 5 :12 3rd Qu.:10.501
HA2015_E11BF.bam: 1 6 :12 Max. :23.047
(Other) :132 (Other):66
以下是生成線圖的代碼:
plt <- ggplot(data.t.m, aes(time, value, group = side, colour = side))
plt <- plt + stat_summary(fun.y = "mean", geom="line", size = 2, position=position_dodge(0.95))
plt <- plt + stat_summary(fun.data="calc.sem", geom="errorbar")
生成的圖如下...
現在我的問題是我如何在ggplot上添加與每個時間點相對應的點數?
可能是你的點隱藏在你的線下面,尺寸= 2。 將geom_point中的磅值設置為更大的大小可以解決您的問題。 請參閱下面的示例,我為時間序列的第一部分模擬了數據,並輕松省略了錯誤欄。
數據示例
df<-data.frame(time=as.factor(c(1,1,2,2,3,3,4,4,5,5)), value=as.numeric(c(7, 8, 9, 10, 10, 11, 10.5, 11.4, 10.9, 11.6)), side=as.factor(c("E","F","E","F","E","F","E","F","E","F")))
Ggplot
library(ggplot2)
p<-ggplot(df, aes(time,value, group=side, colour=side)) + geom_line(size=1)
p<-p+geom_point(size=4)
p
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.