[英]How to fix scale_color_manual? This is not working properly anymore
我目前在 ggplot2 中與 scale_color_manual 作斗爭,盡管這從來都不是問題。 我不斷收到錯誤消息:“錯誤:手動比例中的值不足。需要 9,但只提供了 0。” 但是,我清楚地提供了足夠的 colors,所以它似乎沒有注冊。 有誰知道發生了什么/我該如何解決這個問題?
我的 ggplot2 package 版本是:3.3.3。 Phyloseq 版本是 1.30.0
library(phyloseq)
library(ggplot2)
data("GlobalPatterns")
GP <- prune_species(speciesSums(GlobalPatterns) > 0, GlobalPatterns)
#this usually works to assign colors below
cohortcol<- c("#70AD47","orange", "blue", "green","red",
"yellow","purple","black","grey")
a<-plot_richness(GP, x="SampleType", color="SampleType",
measures=c("Chao1", "Shannon")) +
scale_color_manual(values=alpha(cohortcol, 0.7)) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
legend.position="none", axis.title.y = element_blank())
print(a)
然后它不打印 a 並給我我的錯誤消息。 如果我要刪除群組,我會收到相同的消息,而只是將 colors 添加為向量。
GP 是 phyloseq object。
重新啟動 R 曾經可以解決問題,但是,即使這樣現在也停止了工作。
謝謝你的幫助!
您需要為ggplot2
cohortcol
哪種顏色與數據中的哪些值匹配
如果您這樣做,您的代碼應該可以正常工作
cohortcol<- c("#70AD47","orange", "blue", "green","red",
"yellow","purple","black","grey")
names(cohortcol) <- c("Feces", "Freshwater", "Freshwater (creek)",
"Mock", "Ocean", "Sediment (estuary)", "Skin", "Soil", "Tongue")
這是完整的工作代碼。 我沒有太多使用 phyloseq,但在您的代碼中存在多個關於已棄用 function 的警告,請注意這一點。
library(phyloseq)
library(ggplot2)
data("GlobalPatterns")
GP <- prune_species(speciesSums(GlobalPatterns) > 0, GlobalPatterns)
#> Warning: 'prune_species' is deprecated.
#> Use 'prune_taxa' instead.
#> See help("Deprecated") and help("phyloseq-deprecated").
#> Warning: 'speciesSums' is deprecated.
#> Use 'taxa_sums' instead.
#> See help("Deprecated") and help("phyloseq-deprecated").
#this usually works to assign colors below
cohortcol<- c("#70AD47","orange", "blue", "green","red",
"yellow","purple","black","grey")
names(cohortcol) <- c("Feces", "Freshwater", "Freshwater (creek)",
"Mock", "Ocean", "Sediment (estuary)", "Skin", "Soil", "Tongue")
plot_richness(GP, x="SampleType", color="SampleType",
measures=c("Chao1", "Shannon")) +
scale_color_manual(values=alpha(cohortcol, 0.7)) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
legend.position="none", axis.title.y = element_blank())
由代表 package (v2.0.0) 於 2021 年 5 月 1 日創建
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.