R语言绘图调整绘图图形的背景色

 

ggplot中

001、默认绘图背景颜色

library(ggplot2)
ggplot(mtcars , aes(x=mpg, y=wt)) +
  geom_point()                         ## 测试默认绘图颜色

 

 

002、调整绘图的背景颜色

ggplot( mtcars , aes(x=mpg, y=wt)) +
  geom_point()+
  theme(panel.background = element_rect(fill = "purple"))      ## 设定绘图的背景颜色为紫色

 

 

003、指定绘图区域外的背景颜色

ggplot( mtcars , aes(x=mpg, y=wt)) +
  geom_point()+
  theme(plot.background = element_rect(fill = "purple"))    ## 修改绘图区域外的背景颜色

 

 

004、同时对绘图区域和绘图区域外设置背景颜色

ggplot( mtcars , aes(x=mpg, y=wt)) +
  geom_point()+
  theme(plot.background = element_rect(fill = "purple"),  ## 同时修改绘图区域和绘图区域意外的修改区域
        panel.background = element_rect(fill = "cyan"))+
  ggtitle("xxxxxxxxx")+
  theme(plot.title =element_text(size=20,color ="red",hjust =0.5))

 

 

原文链接:https://zhuanlan.zhihu.com/p/378827656

 

posted @ 2022-09-11 16:25  小鲨鱼2018  阅读(1582)  评论(0编辑  收藏  举报