I have previously asked a question on plotting a barplot with standard errors in R. Creating barplot with standard errors plotted in R. The answer worked perfectly for what I needed. However, I would like to ask if it is possible to modify the graphics of the plot.
Firstly, how do I modify the widths of each factor on the x-axis so that each bar is equal? So in the example below, site B will be wider so the widths of each bar for "before", "during" and "after" are equal.
Secondly, in reality I have more factors than these three, but the plot (irritatingly) should not have colour. I can't find anything on fill effects for plotting a pattern on each bar. So possibly a white background with black diagonal line for some, such as in this picture. Is this possible in ggplot? If so, grey and black fills for "before" and "after", with some kind of pattern for "during" would be ideal.
Apologies for the specificity, but I can't find a way to alter the widths consistently for each site and update fill effects.
Here's an example dataset:
site <- c(rep("a", 8),
rep("b", 11),
rep("c", 8))
values <- as.data.frame(matrix(sample(0:10, 3*9, replace=TRUE), ncol=1))
when <- as.factor(c(rep(c("Before","After"),each = 4),
rep("During", 3),
rep("Before", 4),
rep("After", 4),
rep(c("Before","After"),each = 4)))
df <- data.frame(when,site,values)
Here is the output I have arrived at thus far:
library(plotrix)
library(dplyr)
library(ggplot2)
grouped_df<-group_by(df,when,site)
summarised_df<-summarise_each(grouped_df,funs(mean=mean,std_error=std.error))
limits <- aes(ymax = mean + std_error, ymin=mean-std_error)
g<-ggplot(summarised_df,aes(site,mean,fill=when))
g<-g+geom_bar(stat = "identity",position = position_dodge())
g<-g+geom_errorbar(limits,width=0.25,position = position_dodge(width = 0.9))
g
Thank you in advance for any help on modifying these graphics.