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 @   小鲨鱼2018  阅读(1752)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
点击右上角即可分享
微信分享提示