I have a ggplot containing 2 layers geom_point
and geom_line
as shown below.
gp <- ggplot(data = mtcars , aes(x = disp , y = hp)) +
If you wish to replace the existing size with a smaller one (or replace a solid linetype with a dashed one, a filled shape with an unfilled one, etc.), overlaying may not have the best visual effect. As an alternative, you can dig into the specific layer of the ggplot object you've created, & manually change the parameters there.
(Note that this requires you to know the order of geom layers in the object.)
gp$layers[[2]]$aes_params$size <- 0.5 # change the size of the geom_line layer from 1 to 0.5
gp$layers[[1]]$aes_params$size <- 1 # change the size of the geom_point layer from 3 to 1
I assume your use case involves modifying a ggplot object outputted by some package's plotting function? Otherwise, it's probably simpler to specify the desired parameters at the point of plot creation...