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()) ## 去除背景颜色
绘图结果如下:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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语言中数组中元素的个数