ggplot2中去除背景网格、背景颜色、边框

 

001、theme_classic() 主题用来去除背景

a、使用默认的背景

type <- c('A', 'B', 'C', 'D', 'E', 'F', 'G')
nums <- c(10,23,8,33,12,40,60)
df <- data.frame(type = type, nums = nums)            ## 测试数据

ggplot(df, aes(type, weight = nums))  + geom_bar()    ## 使用默认的背景

绘图结果如下:

 

b、theme_classic() 主题去除背景

type <- c('A', 'B', 'C', 'D', 'E', 'F', 'G')
nums <- c(10,23,8,33,12,40,60)
df <- data.frame(type = type, nums = nums)              ## 保持测试数据不变

ggplot(df, aes(type, weight = nums))  + geom_bar() +
  theme_classic()                                       ## 使用 theme_classic()去除背景

如下为绘图结果:

 

002、手动去除背景网格

type <- c('A', 'B', 'C', 'D', 'E', 'F', 'G')
nums <- c(10,23,8,33,12,40,60)
df <- data.frame(type = type, nums = nums)           ## 保持测试数据不变

ggplot(df, aes(type, weight = nums))  + geom_bar() +
  theme(panel.grid=element_blank())                  ## 手动去除背景网格

 

003、手动去除背景颜色

type <- c('A', 'B', 'C', 'D', 'E', 'F', 'G')
nums <- c(10,23,8,33,12,40,60)
df <- data.frame(type = type, nums = nums)             ## 保持测试数据不变

ggplot(df, aes(type, weight = nums))  + geom_bar() +
  theme(panel.background = element_blank())            ## 去除背景颜色

绘图结果如下:

 

posted @   小鲨鱼2018  阅读(4119)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-03-22 linux中将矩阵数据转换为一行数据
2022-03-22 linux中将矩阵数据转换为一列数据
2022-03-22 linux中如何将一列数据转换为一行数据
2021-03-22 c语言中数组中元素的个数
点击右上角即可分享
微信分享提示