Search code examples
rggplot2geom

How do I remove legend/grid without using theme_void()?


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


Solution

  • 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
        )