I am working on a rather simple graphing project and cannot get the position_dodge
code to work for my triple grouped bar plot in ggplot2.
My small melted data frame is here:
structure(list(month = c(6, 7, 8, 6, 7, 8, 6, 7, 8), variable = structure(c(1L,
1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("Min", "Max", "Avg"
), class = "factor"), value = c(1.3, 2.52258064516129, 4.28709677419355,
1.85666666666667, 2.13870967741935, 4.06129032258064, 1.56666666666667,
2.32903225806452, 4.16129032258065)), row.names = c(NA, -9L), .Names = c("month",
"variable", "value"), class = "data.frame")
The plot code that works does not contain position_dodge
which is here:
ggplot(PJM.data, aes(x= factor(month), y= value, fill = variable)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(label= paste(round(value, digits = 1), "°F", sep = ""), vjust= -0.25))+
scale_fill_manual("Temperature Mean", values= c("steelblue","firebrick1","gold2"))+ ggtitle("Summer 2016 PJM Temperatures") +
labs(y= "Temperature Anomaly°F")
It produces this image:
Every time I attempt to add position_dodge
into my geom_text
portion of my code, the plot trips up and gives me this error:
Don't know how to automatically pick scale for object of type PositionDodge/Position/ggproto. Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (9): label, vjust, position, x, y, fill
I've attempted to change the width value of the position_dodge to many different values and even included the same argument into the geom_bar section. I've consulted both similar posts (Position geom_text on dodged barplot and Position geom_text on dodged barplot), but I cannot figure out why those simple solutions don't work for my data.
Any suggestions?
Thanks.