I would like to dynamically modify/create an aesthetic without recreating a geom layer. Following is my code.
library("ggplot2")
dat <- data.frame(A = c(0,1,2,5,4,3),
B = c(4,1,3,2,0,5),
)
ggplot(data = dat) + geom_point(mapping = aes(x = A, y = B))
Now, I want to add a color aesthetic without recreating a geom_point layer.
ggplot(data = dat) + geom_point(mapping = aes(x = A, y = B, color = A>3))
Here I have to modify the geom_point to add an aesthetic. The idea is to have the dots always plotted and dynamically modify the colours. Is it possible do this without recreating or modifying a geom layer?
I believe you can simply do:
ggplot(data = dat) + geom_point(mapping = aes(x = A, y = B)) + aes(color = A>3)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With