library(ggplot2)
## Warning: 程辑包'ggplot2'是用R版本4.2.3 来建造的
basic <- ggplot( mtcars , aes(x=mpg, y=wt)) +
geom_point()
basic

ggplot( mtcars , aes(x=mpg, y=wt)) +
geom_point()+
theme(plot.background = element_rect(color = "red",
size = 3))
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## i Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

ggplot( mtcars , aes(x=mpg, y=wt)) +
geom_point()+
theme(plot.background = element_rect(color = "red",
size = 3),
plot.margin = margin(t = 10, # top
r = 40, # right
b = 40, # below
l = 10,
unit = "pt")) #left

ggplot( mtcars , aes(x=mpg, y=wt)) +
geom_point()+
theme(plot.background = element_rect(color = "green",
size = 3),
plot.margin = margin(t = 0, # top
r = 0, # right
b = 0, # below
l = 0,
unit = "cm")) #left

ggplot( mtcars , aes(x=mpg, y=wt)) +
geom_point()+
theme(plot.background = element_rect(color = "green",
size = 5),
plot.margin = margin(t = 0, # top
r = 0, # right
b = 0, # below
l = 0,
unit = "cm")) #left
