2017-03-15 106 views
1

我有一個數據象下面這樣:箱線圖/點陣圖

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)) 

我想執行1柱和2之間的成對比較。重要的是所有這些行都創建了一個實體。所以一般來說,兩個小組由成員比較。我只想表明這些團體的成員非常相似。我想到了簡單的boxplot/dotplot,但是如何將這些數據標準化以將所有內容放在一張圖上?你有沒有想過其他的比較?如何把兩個數據集中的數字放到一個圖中?

編輯: 只要忘記提及,我想避免計算它們之間的比率並繪製輸出。

+0

如果只是點對點,[斜坡圖]怎麼樣(https://acaird.github.io/computers/r/2013/11/27/slopegraphs-ggplot)? – JasonAizkalns

+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

您也可以嘗試位數標準化數據,以便更好地比較個人。

+0

它看起來像我可以接受的輸出,但你不認爲它有點太凌亂了嗎?如果我們能夠把這些點的標籤完全搞定,那就太好了。 –

+0

你可以在'ggrepel'包中使用'geom_text_repel'來完成這個 – tbradley

+0

@Jimbou,這兩個解決方案都很好看。特別是,我欣賞第二個! –