Boxplot / dotplot是为了可视化差异

时间:2017-03-15 13:31:57

标签: r

我有如下数据:

structure(c(170007558.204312, 3151225505.1608, 3228057474.07417, 
            131519574.092116, 2149477968.81888, 1215136556.10718, 160433707.919651, 
            5956246992.50776, 2558167135.01689, 3245672969.97675, 169100005.594611, 
            354825870.40362, 1576805307.20395, 416870647.054276, 3399878725.25131, 
            370231854.581136, 1122345506.21081, 2305206508.74322, 2232159732.1229, 
            47308024.505238, 1241395335.9693, 2436980532.07484, 1128618969.34889, 
            3100422173.38636, 288672329.474137, 2987525983.71596, 3287998115.95645, 
            152127227.856302, 1994141536.64711, 1239229228.43808, 145289220.860244, 
            5376086563.26477, 2288378963.83637, 3084446977.22353, 63805766.33001, 
            336627137.967236, 1459357039.40439, 338887231.409886, 2712985868.45896, 
            351047105.326338, 1097447659.97404, 2042978821.82768, 2197665385.69067, 
            38049639.2725552, 1145898075.14945, 2394369287.02634, 941453724.349293, 
            2879533609.52787), .Dim = c(24L, 2L), .Dimnames = list(c("Mark", 
                                                                     "Chris", "Tom", "Tim", "Hank", "Taylor", 
                                                                     "Moniqe", "Rasp", "Greg", "Mephist", "Daniel", 
                                                                     "Moussa", "Ivan", "Treate", "Argen", "Tupol", 
                                                                     "Gotrek", "Marcel", "Gotae", "Ernsten", "Alfred", 
                                                                     "Katrin", "Paul", "Marten"), NULL))

我想在列12之间执行成对比较。重要的是,所有这些行都以某种方式创建了一个实体。因此,通常会按成员比较两组。我只想表明这些团体的成员真的很相似。我想过简单的boxplot / dotplot,但是如何将这些数据标准化以将所有内容放在一个图表上?你有没有其他任何比较?如何将两个数据集中的数字放入一个图表中?

编辑: 别忘了提到我想避免计算它们之间的比例并绘制输出。

1 个答案:

答案 0 :(得分:6)

你可以尝试

library(reshape2)
dl <- melt(d)
plot(dl[,2], dl[,3])
for(i in 1:nrow(d)){
  lines(1:2, c(d[i,]))
}

enter image description here

你也可以试试ggplot解决方案

ggplot(dl, aes(x=factor(Var2), y= value, group=Var1, label=Var1)) + geom_line() + 
  geom_text(data = subset(dl, Var2 == "1"), hjust = 1) +
  geom_text(data = subset(dl, Var2 == "2"), hjust = 0) +
  theme_classic()

enter image description here

在tidyverse你可以写

library(tidyverse)
library(ggrepel)
as.data.frame(d) %>%
  add_column(Names=rownames(d)) %>% 
  gather(key, value, -Names) %>% 
  ggplot(aes(x=key, y=value,label=Names)) +
  geom_boxplot(fill="grey") +
  geom_line(aes(group=Names)) + 
  geom_text_repel(size=3, color="red") +
  theme_classic()

enter image description here

另一种方法是转动图并在y轴上显示名称。

ggplot(dl, aes(x= value, y=Var1, col = factor(Var2))) + geom_point()  + theme_bw()

enter image description here

您还可以尝试对数据进行中值标准化,以便更好地比较个体。