I know there are ways to update settings of a given ggplot graph.
I want to save two files, one with the standard setting as png and another one as pdf but with a different label size.
df <- data.frame(a=c('a;b;c','d;e;f'), b=c('A;B;C','D;E;F'),
x=c(1,2), y=c(2,3))
g <- ggplot(df, aes(x,y)) + geom_point() + geom_text(aes(label=a))
ggsave('test1.png',g)
ggsave('test2.pdf',g + geom_text(aes(label=a), size=10))
Is there a way to remove or update the old geom_text layer and not just add a layer to the graph?
Look into str(g)
and update relevant bits, in your case following should work:
g$layers[[2]]$geom_params$size <- 10
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