R ggplot2 bar chart facet wrap with scales=free and y axis starting at nonzero value -
i'm using r , ggplot2 package create plot containing multiple subplots, each of bar chart error bars. each subplot must have separate y scale because min , max values vary respect facet. constraint have want bar chart start @ non-zero values (similar way box plots, violin plots, or dot plots work). i've tried far:
# simulation data volumes1 <- rnorm(40, mean=4, sd=0.2) volumes2 <- rnorm(40, mean=35, sd=1) region1 <- rep('cerebrum', times=40) region2 <- rep('cerebellum', times=40) name1 <- rep('name1', times=20) name2 <- rep('name2', times=20) names <- rep(c(name1, name2), times=2) genotypes <- rep(c('g1', 'g2'), times=40) meansdata <- data.frame(name=names, genotype=genotypes, region=c(region1, region2), volume=c(volumes1, volumes2)) # ggplot2 library(ggplot2) library(hmisc) meansplot = ggplot(data=meansdata, aes(x=name, y=volume, fill=genotype, colour=genotype)) meansplot = (meansplot + stat_summary(fun.y=mean, position=position_dodge(width=1), geom='bar') + stat_summary(fun.data=mean_cl_normal, position=position_dodge(width=1), geom='errorbar', color='black', size=0.5, width=0.5)) meansplot = (meansplot + facet_wrap( ~ region, scales='free')) meansplot everything's except fact bar chart reason has start @ 0, differences between bars become less visible. pretty ugly if ask me. i've tried adding in scale_y_continuous, works when plot has 1 subplot , makes bars disappear, not desired.
let me know if have solution how start @ non-zero value y-axis scaling! lot. thank you.
Comments
Post a Comment