I'm also having an issue with this code but this forum won't let me post two new topics in one day so I'll add it here for anyone that has any ideas!
I managed to get this code to work yesterday and successfully built a bar graph displaying two variables. Today when I go to rerun the code in order to make adjustments I'm getting code errors with my data. I assume it has something to do with my month data but I don't know what to do any help would be apprecaited!
#Plot 2 code
library(reshape)
Month <- factor(levels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
P1941TO1970 <- c(67.8, 53.1, 56.1, 81.5, 64.2, 56.9, 71.8, 71.1, 73.4, 67.5, 72.4, 60)
P1970TO2010 <- c(64, 57.8, 68.4, 79.1, 79.4, 84.9, 100.7, 79.2, 81.9, 77.4, 84.3, 73)
df <- data.frame(Month, P1941TO1970, P1970TO2010)
here is where I get the error "Error in data.frame(Month, P1941TO1970, P1970TO2010) : arguments imply differing number of rows: 0, 12" but this data all variables have the same number of rows, 12.
require(tidyr)
df.long <- gather(df, variable,value, -Month)
ggplot(data = df.long, aes(x = Month, y = value, fill = variable)) +
geom_col(position = position_dodge()) +
labs(title = "Hamilton Precipitation from 1941-2010", x = "Month", y = "Precipitation (mm)") +
theme(axis.title=element_text(size=10)) +
theme(axis.text=element_text(size=12)) +
theme(plot.title=element_text(size=12, hjust=0.5, face = 'bold')) +
theme(
legend.position = c(0.13, 0.9),
legend.margin = margin(2, 2, 2, 2),
legend.text = element_text(size = 8),
legend.title = element_blank()
)