Search code examples
rggplot2ggthemes

How to remove black border around plots/graphics in ggplot2? R


I'm creating some plots but every one I make has a black square border? How can I make this border white or remove it completelty?

Here is my code

library(ggplot2)
library(ggthemes)

ggplot(mtcars, aes(x = mpg)) + 
  geom_point(aes(y = hp)) + 
  theme_clean(base_size=18)


Here is my output plot that pasted into paint and used red arrows to point at the black border around my plot

enter image description here

How can I remove the black square border?


Solution

  • Edit the plot.background element of theme, changing color to white

    library(ggplot2)
    library(ggthemes)
    data(mtcars)
    ggplot(mtcars, aes(x = mpg)) +
      geom_point(aes(y = hp)) +
      theme_clean() +
      theme(plot.background = element_rect(
        color = "white"
      ))
    

    enter image description here