r - R如何将列名添加为标题
问题描述
plots <- data %>%
select( contains("Pct")) %>%
map(~ggplot(data, aes(y= . , x = Project_Name ,fill=Project_Name,)) +
geom_boxplot(alpha=0.7) +
theme(legend.position="none", axis.title.x=element_blank() , axis.text.x=element_blank() )+
labs(title=names(.)) +
scale_fill_brewer(palette="Dark2"))
ggarrange(plotlist = plots,common.legend = TRUE)
使用上面的代码,我能够获得绘图但无法获得 y 轴标签,我可以将选定的列名称添加为 y 轴标签还是绘图标题(名称(。))不起作用。
解决方案
这可以通过使用purrr::imap
代替来实现map
。
使用iris
示例数据试试这个:
library(ggplot2)
library(dplyr)
library(ggpubr)
library(purrr)
plots <- iris %>%
select(contains("Petal")) %>%
imap(~ggplot(iris, aes(y = .x , x = Species , fill=Species)) +
geom_boxplot(alpha=0.7) +
theme(legend.position="none", axis.title.x=element_blank() , axis.text.x=element_blank() )+
labs(title=.y) +
scale_fill_brewer(palette="Dark2"))
ggarrange(plotlist = plots, common.legend = TRUE)
推荐阅读
- python - 使用 one-hot 编码将列表转换为二进制值
- django - 如何使用 django rest Framework 的搜索过滤器在多个模型中进行搜索
- javascript - 在 Matter,js 中为凹面 SVG 组合添加边框
- android - 如何在 IMA SDK Android 中整合来自 Google adsense 的广告?
- python - 注销循环时如何计算误报率 (FPR) 的平均值?
- python - Python SQL Server数据库循环不起作用
- python - 如何修复 Django serializers.py 字段中的错误
- flutter - 如何将 curl 命令转换为 http 方法
- next.js - 在 Next.js SSR/ISR 中使用和不使用重新验证的情况下,回退 false 与 true 与阻塞 getStaticPaths 有什么区别?
- multithreading - 如何在 PS 后台作业和线程作业中跟踪 powershell 脚本调用模式?