r - Can the minimum y-value be adjusting when using scales = "free" in ggplot? -
using following data set:
day <- gl(8,1,48,labels=c("mon","tues","wed","thurs","fri","sat","sun","avg")) day <- factor(day, level=c("mon","tues","wed","thurs","fri","sat","sun","avg")) month<-gl(3,8,48,labels=c("jan","mar","apr")) month<-factor(month,level=c("jan","mar","apr")) snow<-gl(2,24,48,labels=c("y","n")) snow<-factor(snow,levels=c("y","n")) count <- c(.94,.95,.96,.98,.93,.94,.99,.9557143,.82,.84,.83,.86,.91,.89,.93,.8685714,1.07,.99,.86,1.03,.81,.92,.88,.9371429,.94,.95,.96,.98,.93,.94,.99,.9557143,.82,.84,.83,.86,.91,.89,.93,.8685714,1.07,.99,.86,1.03,.81,.92,.88,.9371429) d <- data.frame(day=day,count=count,month=month,snow=snow)
i y-scale in graph, not bars:
ggplot()+ geom_line(data=d[d$day!="avg",],aes(x=day, y=count, group=month, colour=month))+ geom_bar(data=d[d$day=="avg",],aes(x=day, y=count, fill=month),position="dodge", group=month)+ scale_x_discrete(limits=levels(d$day))+ facet_wrap(~snow,ncol=1,scales="free")+ scale_y_continuous(labels = percent_format())
i points, not scale:
ggplot(data=d[d$day=="avg",],aes(x=day, y=count, fill=month,group=month,label=month),show_guide=f)+ facet_wrap(~snow,ncol=1,scales="free")+ geom_line(data=d[d$day!="avg",],aes(x=day, y=count, group=month, colour=month), show_guide=f)+ scale_x_discrete(limits=levels(d$day))+ scale_y_continuous(labels = percent_format())+ geom_point(aes(colour = month),size = 4,position=position_dodge(width=1.2))
- how combine desirable qualities in above graphs?
essentially, i'm asking: how can graph points varied y-max while setting y-min zero?
note: solution i'm aiming find apply 27 graphs built 1 dataframe. i'll vote solutions avoid alterations individual graphs. i'm hoping solution applies facet wrapped graphs.
minor questions (possibly separate post): - how can add legend each of facet wrapped graphs? how can change title of legend read "weekly average"? how can shape/color of lines/points varied , reported in 1 single legend?
there's expand_limits(y=0)
, adds dummy layer invisible geom_blank
stretch scales.
Comments
Post a Comment