Here\'s the minimal case:
df <- data.frame(x=1:5, y=1, col=1:5)
mapping <- aes(x=x, y=y)
ggplot(df, mapping) + geom_point(size=10)
N
Based on @koshke's comment, here's a working example that does the job:
df <- data.frame(x=1:5, y=1, new_y=5:1, col=1:5, new_col=factor(1:5))
mapping <- aes(x=x, y=y, col=col)
ggplot(df, mapping) + geom_point(size=10)
add_modify_aes <- function(mapping, ...) {
ggplot2:::rename_aes(modifyList(mapping, ...))
}
ggplot(df, add_modify_aes(mapping, aes(color=new_col, y=new_y))) + geom_point(size=10)
There's a slight modification that deals with aes collisions (i.e., col
, color
, colour
).
Initial plot: Modified plot: