目前,我正在创建一个具有多个生物分类群的相对丰富的地理区域。但是,我想根据分类群的“系统发育”来添加多种颜色的梯度,来划分每个“分类群”属于哪个门。本质上,我现在要说的是:
library(ggplot2)
library(scales)
require(reshape2)
require(plyr)
taxdat <- read.table("fig_2.txt", header = TRUE, row.names = 1)
data <- melt(cbind(taxdat, taxa = rownames(taxdat)), id.vars = c('taxa'))
#order factor
data$taxa <- factor(data$taxa, levels=unique(data$taxa))
ggplot(data,aes(x = variable, y = value, fill = taxa)) +
geom_bar(position = "fill",stat = "identity") +
scale_y_continuous(labels = percent_format()) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank())产生了这个..。
然而,我想根据属于的门对每个分类进行颜色编码,但仍然保留单独的梯度来区分分类群。例如,橙色的“节肢动物”,绿色的“涅玛塔”等。任何帮助将不胜感激。
谢谢,迪恩
这是税收数据,如果你想要的话:
Abund Phylogeny
Metazoa 13 Metazoa
Arthropoda 3 Arthropoda
Arachnida 3 Arthropoda
Alicorhagia 3 Arthropoda
Araneae 2 Arthropoda
Harpacticoida 1 Arthropoda
Lepidoptera 6 Arthropoda
Oribatida 4 Arthropoda
Gehypochthonius 1 Arthropoda
Coccinellidae 5 Arthropoda
Salticidae 3 Arthropoda
Liochthonius 3 Arthropoda
Paraphidippus 1 Arthropoda
Paucitubulatina 4 Gastrotricha
Chaetonotidae 1 Gastrotricha
Nematoda 30 Nematoda
Chromadorea 5 Nematoda
Dorylaimida 2 Nematoda
Plectidae 1 Nematoda
Prismatolaimus 2 Nematoda
Alaimus 2 Nematoda
Geomonhystera 10 Nematoda
Mesodorylaimus 1 Nematoda
Prodesmodora 1 Nematoda
Tylocephalus 1 Nematoda
Eutardigrada 1 Tardigrada
Parachela 2 Tardigrada更新:我已经用系统发育数据修改了分类法元数据,所以如果只是复制和粘贴,上面的代码就不会顺利运行。
发布于 2017-03-23 22:00:23
我会考虑一下如何最有效地可视化这些数据。颜色的一个问题是,超过一定数量的类别(约8种),它们作为区分类别的手段变得无效。因此,在你的情况下,他们可以工作门,但不是分类群。另一个考虑因素:有了一个以上的因素,你通常需要一个以上的因素分组方法(即多颜色)。
定义您希望可视化解决的问题。“我想快速了解每个门的主要分类群”。这里有一个ggplot建议来解决这个问题。我假设您的数据位于一个数据框架data中,其中有一个名为Taxa的列,而不是在行名中。
library(ggplot2)
ggplot(data, aes(Taxa, Abund)) + geom_col() +
facet_grid(Phylogeny ~ .) + theme_light() +
theme(axis.text.x = element_text(angle = 90))结果:

您还可以考虑ggplot之外的其他工具和方法。例如,另一种在层次类别中可视化比例的方法是树状图:
library(treemap)
treemap(data, index = c("Phylogeny", "Taxa"), vSize = "Abund",
vColor = "Abund", palette = "Spectral")结果(需要改进):

https://stackoverflow.com/questions/42960227
复制相似问题