Logo Questions Linux Laravel Mysql Ubuntu Git Menu

ggplot update and not add a layer




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('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?

like image 540
drmariod Avatar asked Mar 17 '23 07:03


1 Answers

Look into str(g) and update relevant bits, in your case following should work:

g$layers[[2]]$geom_params$size <- 10
like image 101
zx8754 Avatar answered Mar 28 '23 16:03