当某些组有多个人但另一些只有一个人时,哪种可视化数据更好的方法是什么?

时间:2018-10-05 00:15:47

标签: r ggplot2 data-visualization

我试图绘制属于五个亚属(组)的物种的不同基因的突变率。对于某些组,有多个物种,但对于另一些组,只有一个物种。在R中使用ggplot2的Boxplot可以正常工作,但是很难区分不同的组,尤其是只有一个物种的组。

在这种情况下,关于哪种类型的图更好的建议?

这是箱线图的结果: png of boxplot using ggplot2

我用来获取箱线图的代码是:

ggplot(data = df) + geom_boxplot(mapping = aes(x=dS, y = Genes, color = Subgenus))

这是我的数据(仅对于第一个基因):

df <- tibble(Subgenus =c("Adenia", "Astrophea", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Deidamiodies", "Deidamiodies", "Deidamiodies", "Deidamiodies", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Tetrapathea"), Species = c("A.mannii", "P.pittieri", "P.affinis", "P.auriculata_FG", "P.auriculata_S", "P.biflora", "P.filipes", "P.jatusachensis", "P.lutea", "P.microstipula", "P.misera", "P.rufa", "P.suberosa", "P.tenuiloba", "P.arbelaezii", "P.cirrhifolia", "P.contracta", "P.obovata", "P.actinia", "P.cincinnata", "P.edulis", "P.foetida", "P.laurifolia", "P.ligularis", "P.menispermifolia", "P.nitida", "P.oerstedii", "P.quadrangularis", "P.retipetala", "P.serratifolia", "P.serratodigitata", "P.vitifolia", "P.tetrandra"), Genes = c("atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA"), dS = c("0.2929", "0.2596", "0.3069", "0.3178", "0.3138", "0.3014", "0.3009", "0.3293", "0.292", "0.2894", "0.32", "0.3154", "0.334", "0.339", "0.28", "0.2946", "0.2841", "0.2947", "0.2959", "0.3153", "0.2939", "0.3095", "0.2988", "0.2964", "0.3177", "0.2928", "0.3145", "0.2933", "0.314", "0.3037", "0.2995", "0.2981", "0.2807"))

2 个答案:

答案 0 :(得分:2)

考虑制作热图:您可以将“基因和物种”用作列或行(受实际数据集的尺寸所施加的约束),然后用颜色和文本对dS进行双重编码。这种布局可以轻松地将物种分组到亚属中。

您的数据集,用无意义的数据扩展以说明这一点

library(ggplot2)
library(dplyr)
df <- tibble(Subgenus =c("Adenia", "Astrophea", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Decaloba", "Deidamiodies", "Deidamiodies", "Deidamiodies", "Deidamiodies", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Passiflora", "Tetrapathea"), Species = c("A.mannii", "P.pittieri", "P.affinis", "P.auriculata_FG", "P.auriculata_S", "P.biflora", "P.filipes", "P.jatusachensis", "P.lutea", "P.microstipula", "P.misera", "P.rufa", "P.suberosa", "P.tenuiloba", "P.arbelaezii", "P.cirrhifolia", "P.contracta", "P.obovata", "P.actinia", "P.cincinnata", "P.edulis", "P.foetida", "P.laurifolia", "P.ligularis", "P.menispermifolia", "P.nitida", "P.oerstedii", "P.quadrangularis", "P.retipetala", "P.serratifolia", "P.serratodigitata", "P.vitifolia", "P.tetrandra"), Genes = c("atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA", "atpA"), dS = c("0.2929", "0.2596", "0.3069", "0.3178", "0.3138", "0.3014", "0.3009", "0.3293", "0.292", "0.2894", "0.32", "0.3154", "0.334", "0.339", "0.28", "0.2946", "0.2841", "0.2947", "0.2959", "0.3153", "0.2939", "0.3095", "0.2988", "0.2964", "0.3177", "0.2928", "0.3145", "0.2933", "0.314", "0.3037", "0.2995", "0.2981", "0.2807"))
i <- 1
while (i < 5) { i <- i + 1; df <- rbind(df, df)}
for (x in 1:16) { df[1*x:33*x, 'Genes'] <- paste0('atpA', x)}

绘制热图,如果dS是字符,则无法进行有意义的比较

df$dS <- as.numeric(df$dS)
ggplot(data = df, aes(y = Species, x = Genes)) + 
    geom_tile(aes(fill = dS)) + 
    geom_text(aes(group = Subgenus, label = dS), size = 3) +
    facet_grid(Subgenus ~., scales = 'free') + 
    theme_bw()

enter image description here

答案 1 :(得分:2)

如果重点是比较突变率(我假设为dS),请考虑使用该变量来定义您的排序顺序,而不是按字母顺序对基因进行排序。

思考和试验您想在视觉上突出显示哪些比较可能也很有用:是物种间,亚属间还是基因间dS的差异?我建议将它们编码为位置或长度,并在视觉上使其相邻并以相同的比例排列。

ggplot(df, aes(x = dS, 
               y = Species %>% fct_reorder(dS), 
               color = Subgenus)) + 
  geom_point() +
  facet_wrap(~Genes) +
  scale_colour_brewer(palette = "Dark2") +
  labs(y="") + theme_bw()

enter image description here