2013-01-03 60 views
0

我有一個看起來像這樣的數據:最佳的可視化方法

 chr01 chr02 chr03 chr04 chr05 chr06 chr07 chr08 chr09 
T10  2  5  3  5  4  1  9  2  3 
T11  0  2  1  5  2  1  3  5  4 
T65  0  5  1  3  4  1  5  3  1 

一些列列的有0。我想要顯示每列中的零的數量(可能是每列的0的百分比內容)。我是R用戶,首先想到使用餅圖,但我想知道是否有任何複雜的表示方法!? 即使我嘗試了heatmap。任何其他方式來表示這? (底線是我想表示明智的每列0的百分比)

回答

1

你也可以使用ggplot2。它給了你更多的控制,儘管我不確定這是否是你要找的眼睛。我不確定你是否要求完全不同類型的可視化,或者如果你正在尋找繪製條形圖(這適用於@Didzis顯示)和更多的控制。對於第二種情況,ggplot2可能是有用的:

require(ggplot2) 
df <- structure(list(chr01 = c(2L, 0L, 0L), chr02 = c(5L, 0L, 5L), 
     chr03 = c(3L, 1L, 0L), chr04 = c(0L, 5L, 0L), chr05 = c(0L, 
     2L, 4L), chr06 = c(0L, 0L, 0L), chr07 = c(9L, 3L, 0L), chr08 = c(2L, 
     0L, 3L), chr09 = c(3L, 4L, 1L)), .Names = c("chr01", "chr02", 
     "chr03", "chr04", "chr05", "chr06", "chr07", "chr08", "chr09" 
     ), class = "data.frame", row.names = c("T10", "T11", "T65")) 
gg.df <- data.frame(chr.id = names(df)) 
gg.df$cnt <- sapply(df, function(x) sum(x==0)/length(x) * 100) 

qplot(factor(chr.id), weight=cnt, data=gg.df, geom="bar", fill=factor(chr.id)) 

這給你:ggplot2 bar plot example
當然,您可以更改此圖的每個元素(查看本文開頭的鏈接)。

+0

謝謝..這是非常有益的.. – PoisonAlien

1

表示結果的簡單方法是製作條形圖。假設你的數據幀被命名爲df

#Calculate percentage of 0 for each column 
pr.0<-apply(df,2,function(x) mean(x==0)*100) 
#Plot results 
barplot(pr.0,ylab="Percentage") 

enter image description here

+0

非常感謝Didzis。這將使我的可視化變得清晰。但是,有沒有我可以爲這些數據創建的任何「視覺糖果」類型圖。 – PoisonAlien

+0

@ user1897329「眼睛糖果」是什麼意思? –

+0

如果我聽起來很愚蠢,我很抱歉,Barchart會滿足我的目的,但有沒有創建視覺吸引力劇情的任何選項?它只是我想探索的選項。非常感謝你的回答。 – PoisonAlien

2

另一種方法是使用dotplot - 您只能用一個點表示您的值。我會用包lattice做的,而不是GGPLOT2這一點,但我在下面,以防萬一這兩個解決方案:

#load df data from @Arun answer, and then... 
library(reshape2)#for melt function 
dd <- apply(df,2,function(x) mean(x==0)*100) 
d1 <- melt(dd)#gets data to long format 
d <- data.frame(variable=rownames(d1), d1) 
#lattice dotplot 
library(lattice) 
dotplot(reorder(variable, value) ~ value, d, col=1, aspect=1, 
     xlab="percentage", ylab="") 

enter image description here

#ggplot2 dotplot 
library(ggplot2) 
ggplot(d, aes(x = value, y = reorder(variable, value))) + 
    labs(x = "percentage", y = "") + 
    geom_point() + 
    theme_bw() 

enter image description here