So, with this data:
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
I need help to standarize my plot creation flow. Option1 is my lifetime way of making a plot, but after reading Hadley's book I'm trying to call
aes() inside the
geom, but I'm getting error.
OPTION 1: works!
ggplot(df, aes(trt, outcome, label = outcome)) + geom_col() + geom_label(vjust = -0.5) + ylim(0,6)
But after reading http://r4ds.had.co.nz/data-visualisation.html
OPTION 2: does not work!
ggplot(df) + geom_col(aes(trt, outcome, label = outcome)) + geom_label(vjust = -0.5) + ylim(0,6)
But I'm getting this error:
Warning: Ignoring unknown aesthetics: label
Error: geom_label requires the following missing aesthetics: x, y, label
I understand that option 2 is mor concise with the theory shared in the data visualization of Hadley's book.
What am I missing to make the second option work?