Doug Mitarotonda
unread,Jul 29, 2015, 3:31:07 PM7/29/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
Hey everyone,
Another question for you all today. I often like to create a “base” plot in a function and then update the aesthetics I want later, which is easy to do with the `aes` function. But if I want to set, not map, later, how do you do that?
library(ggplot2)
dft <- data.frame(x=LETTERS[1:3], y=1:3, stringsAsFactors = FALSE)
basePlot <- function(dft){ ggplot(dft) + geom_bar(aes(x, y), stat = "identity") }
# Now I can do things like, without changing the base plot
basePlot(dft) + aes(fill = x)
basePlot(dft) + aes(alpha = y)
# However, suppose I want to set, not map, alpha, is that possible to do outside of the geom?
# errors
# basePlot(dft) + layer(alpha = 0.5)
Thanks!
Doug