dnem
dnem

Reputation: 89

plot points just for each day like error bars

I have a data that looks something like given below. I want to create a timeseries for each variable A, B, and C with the date on the x axis and min_val ,max_val, and Mean_val as on y axis.

mydata <- data.frame(date=c(as.Date("2015-01-07"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-07"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-08"),
                            as.Date("2015-01-08")),
                     var = c("Min_val_a","Max_val_a","Mean_val_a","Min_val_a",
                             "Max_val_a","Mean_val_a","Min_val_b","Max_val_b",
                             "Mean_val_b","Min_val_b","Max_val_b","Mean_val_b",
                             "Min_val_c","Max_val_c","Mean_val_c","Min_val_c",
                             "Max_val_c","Mean_val_c"),
                     val =c(0.01,0.05,0.03,0.04,0.08,0.06,0.06,0.08,0.07,0.06,0.10,0.08,
                            0.07,0.09,0.08,0.08,0.10,0.09),
                     fvar =c("A","A","A","A","A","A","B","B","B","B","B","B","C","C","C","C","C","C"))

I want to plot something like an error line plot with the code below

ggplot(mydata,aes(x=date,y=val))+
  geom_point()+
  #geom_line()+
  facet_wrap(~fvar)

If I add geom_line, then it looks very messy. Is there a way to connect the dots for each day only?

Upvotes: 0

Views: 41

Answers (1)

benson23
benson23

Reputation: 19107

You can add aes(group = date) in your ggplot.

library(ggplot2)

ggplot(mydata,aes(x=date,y=val, group = date))+
  geom_point()+
  geom_line()+
  facet_wrap(~fvar)

Upvotes: 1

Related Questions