r - 如何重命名图例并在 R 中包含调色板
问题描述
我正在尝试更改图例的标签。该图应用了一个调色板(调色板 npg)。但是,当我重命名图例“10^7”、“10^5”时,颜色会重置为默认调色板。
样本数据集:
Concentration Strain Values1
10000CFU F 0.01
10000CFU F 0.03
10000CFU F 0
10000CFU M3 0.05
10000CFU M3 0.03
10000CFU M3 0
10000CFU M5 0.02
10000CFU M5 0.02
10000CFU M5 0.01
1000000CFU F 0.01
1000000CFU F 0.02
1000000CFU F 0.01
1000000CFU M3 0.05
1000000CFU M3 0.04
1000000CFU M3 0.04
1000000CFU M5 0.12
1000000CFU M5 0.11
1000000CFU M5 0.10
mydata <- read.csv(file.choose(), header=TRUE, sep="\t")
library(ggplot2)
library(ggpubr)
p <- ggboxplot(mydata, x = "Strain", y = "Values1",palette="npg",fill="Concentration") + stat_compare_means(
comparisons = list(c("thing1", "thing2")),
label = "p.signif", method="t.test") +
theme(legend.title=element_blank()) +
theme(legend.position="bottom") + labs(title="Title", x = "Type", y = expression('OD'[600])) + scale_fill_discrete(labels=c(expression('10'^7),expression('10'^5)))
print(p)
有没有办法设置调色板以及重命名图例?如果我使用上面的代码,我会得到下图:
但是,我想使用不同的调色板(例如,调色板 npg)。如果我删除代码
scale_fill_discrete(labels=c(expression('10'^7),expression('10'^5)))
我得到了图表: 没有图例的图表,带有调色板
我对将配色方案应用于图表的替代方法持开放态度。但是,我有很多图表并且希望保持一致。
解决方案
推荐阅读
- php - 如何显示自定义帖子类型的自定义字段
- tensorflow - tensorFlowJs Json 模型问题
- javascript - 如何在 css 上创建这个视图?还是JavaScript?
- azure - Azure 策略修改效果
- java - IMessageReciever.receiveBatch() 的 Azure ServiceBus 奇怪行为
- firebase - 如何在 Flutter 中从 firebase 显示我的 PDF 之前添加循环进度指示器?
- reactjs - 是否可以使用展开运算符来设置反应组件道具?
- autodesk-navisworks - 如何使用 Navisworks API 从 Clash Detective UI 中获取选定的冲突结果项
- css - 将跨度对齐到输入框下方
- node.js - 如何在猫鼬的文档中对数组进行排序?