3
votes

I have a df as below and i wanted to generate time-series plot using geom_line. Here is the summary of my data:

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                                          

Here is the code for generating the line plot:

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

The plot that is generated is as below...

time_series_plot

Now my question is how can i add points corresponding to each of the time points on the ggplot?

1
Isn't this just + geom_point() ? Can you post a reproducible subset of your data using dput()? or some random-seeded data. - smci
i tried geom_point() by i get multiple points instead of single point.... - upendra
Well post us that wrong image, if you can't post us your dataset. - smci

1 Answers

6
votes

It might be that your points are hidden underneath your line which was size=2. Setting the point size in geom_point to a bigger size may resolve your problem. See below an example, I simulated your data for the first part of the time-series and for ease left out the error bars.

Data example

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

enter image description here