2014-04-14 19 views
1

我中的R的例子:使用中的R barplot不同類

mat2 
##  Bos_RM Bos_SM Jac_AGM Jac_RM 
## t34340 22.67389 NA  14 19.60895 
## t60337 18.00000 12.0  NA 19.60895 
## t71357 22.67389 9.5  11 19.60895 

bar = barplot2(t(mat2), 
     beside = TRUE, 
     col = c("red","green","blue","orange"), 
     # legend = colnames(mat2), 
     ylim = c(0, max(na.omit(mat2))+1), 
     ylab="-logpvalue", 
     #xaxt='n', 
     #xlab="", 
     ) 
box() 

生產該圖中:

descricao da imagem

我想產生該圖沒有這些空間(由NA創建S)。

+1

圖中沒有顯示出來和'dput(MAT2)'將是有益的。 – hrbrmstr

+0

爲你添加了情節 – hrbrmstr

回答

1

如果你可以使用ggplot2,這會爲你做它:

mat2 <- read.table(textConnection("Bos_RM Bos_SM Jac_AGM Jac_RM 
t34340 22.67389 NA  14 19.60895 
t60337 18.00000 12.0  NA 19.60895 
t71357 22.67389 9.5  11 19.60895")) 

# convert transpose to data frame 
dat <- data.frame(t(mat2)) 
dat$b <- rownames(dat) 
rownames(dat) <- NULL 

# melt the data for ggplot2 plot 
q <- melt(dat) 

# plot only the bars that aren't NA 
gg <- ggplot(na.omit(q), aes(x=variable, y=value, group=b)) 
gg <- gg + geom_bar(stat="identity", aes(fill=b), position="dodge") 
gg <- gg + labs(x="", y="-logpvalue", title="") 
gg 

變化b到任何有意義的情節。

enter image description here

+0

非常感謝你;-) – quelopes

+0

你知道是否有可能考慮x軸上的名字更接近酒吧,這些名字分別出現在每個組?最好, – quelopes

+0

試圖找出你需要什麼。所以你想刪除「t34340」等之間的空白?另外,你想要在酒吧上的「Bos ...」和「Jac ...」標籤? – hrbrmstr

1

這裏的鹼溶液:

v <- as.vector(t(mat2)) 
bar = barplot(v, 
     beside = TRUE, 
     width = as.integer(!is.na(v)), # set widths based on missingness 
     space = rep(c(1,0,0,0),3), # manually set spacing 
     col = c("red","green","blue","orange"), 
     ylim = c(0, max(na.omit(mat2))+1), 
     ylab="-logpvalue" 
     ) 

enter image description here