0

Here I have theme_light() but in the plot I still have the x/y axis & legend + grid. I want to remove those and only have my light background + plot 'pic'. When I use theme_void -> it removes the legend but then the background is void. Any idea how to solve this so I only have a white background and my plot?

pic <- ggplot(data = art_dat, mapping = aes(x = x, y = y, group = path_id,
                                                color = step_id)
              ) + 
  geom_path(
            size = .9,
            alpha = 1000, #transparency of the lines
            show.legend = FALSE
                        
            ) +
            coord_equal() + 
            theme_light() + 
            scale_color_scico(palette = "berlin")          

enter image description here

tjebo
  • 21,977
  • 7
  • 58
  • 94

2 Answers2

1

EDIT: Updated as you have posted an image. You do not have a legend, so you do not need to remove it. You want to remove the axis lines, ticks, text, title and maybe(?) the panel grid lines:

pic <- ggplot(data = art_dat, mapping = aes(x = x, y = y, group = path_id,
                                                color = step_id)
              ) + 
  geom_path(
            size = .9,
            alpha = 1000, #transparency of the lines
            show.legend = FALSE
                        
            ) +
            coord_equal() + 
            theme_light() + 
            scale_color_scico(palette = "berlin") +
                theme(
        axis.line = element_blank(), 
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        axis.title = element_blank(),
        panel.grid.major = element_blank(), # optional - remove gridlines
        panel.grid.minor = element_blank() # optional - remove gridlines
    )
SamR
  • 8,826
  • 3
  • 11
  • 33
  • with data do you mean the graph? I have tried your suggestion, I think it didn't change anything. – Amouda love Jan 18 '22 at 12:23
  • I mean the data in the data frame, and the plot. See here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example . At the very least you could post an image of the plot you are getting, and what particularly you want to change about it. – SamR Jan 18 '22 at 12:23
  • i added the picture as link. I can't add image yet. Essentially I only want the black & blue little blocks and a white background, nothing else because it is more for an art project than statistics etc. – Amouda love Jan 18 '22 at 12:28
  • OK I see now - I have updated my response. If this is what you want please mark the answer as correct. – SamR Jan 18 '22 at 13:14
1

If you add some adjustments to theme void, you can get rid of the legend. In addition, you can make the legend white with the plot.background argument. In the example below I made it red to show that there are no margins left and such. There is a row of white pixels, but I don't know what to do against that.

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy, colour = cyl)) +
  geom_point()

p + theme_void() +
  theme(
    legend.position = "none",
    plot.background = element_rect(fill = "red", colour = NA)
  )

Created on 2022-01-18 by the reprex package (v2.0.1)

teunbrand
  • 33,645
  • 4
  • 37
  • 63