2017-06-07 11 views
1

私は凡例が行3、列2に表示されるように、5つのbarcharts(2つのcolomnsと3つの行を含む)を含むmultiplotを作りたいと思います。また、(A、B、C ..)各プロットの右上の位置に現れる(m/z = 450.02 RT 9.52、m/z 500.07 RT 10、...)。 また、データSDを含む最初のチャートにエラーバーを追加したいが、プロットに追加できなかった。 このプロットを解くのを手伝ってください。ありがとうございました!複数のプロットで凡例を削除しますか?

ここに私のコンソールです:

data <- data.frame(group = c("B. mamane+SAHAall","B. mamane+SAHAprod","Untreated B. mamane","B. mamane+VSall","B. mamane+VSprod"), 
       intensity = c(7378298.69217025,9009027.95021888,11106773.0180047,3010750.725502,25794620.5038354), 
       sd = c(2554669.97449261,1054643.80319534,4936955.54885355, 1606982.34241596, 9975537.82883142)) 

ヘッド(データ)

data1 <- data.frame(group = c("B. mamane+SAHAall","B. mamane+SAHAprod","Untreated B. mamane","B. mamane+VSall","B. mamane+VSprod"), 
       intensity = c(1089586.025, 
           1622944.618, 
           1466859.571, 
           1213772.715, 
           9310160.875)) 
data2 <- data.frame(group = c("B. mamane+SAHAall","B. mamane+SAHAprod","Untreated B. mamane","B. mamane+VSall","B. mamane+VSprod"), 
       intensity = c(1196693.956, 
           1742096.027, 
           1545728.252, 
           1307935.409, 
           9569069.002)) 

data2 <- data.frame(group = c("B. mamane+SAHAall","B. mamane+SAHAprod","Untreated B. mamane","B. mamane+VSall","B. mamane+VSprod"), 
       intensity = c(1196693.956, 
           1742096.027, 
           1545728.252, 
           1307935.409, 
           9569069.002)) 
data3 <- data.frame(group = c("B. mamane+SAHAall","B. mamane+SAHAprod","Untreated B. mamane","B. mamane+VSall","B. mamane+VSprod"), 
       intensity = c(106964005.1, 
           92622841.82, 
           122723308, 
           159793488.3, 
           153196930.7)) 
data4 <- data.frame(group = c("B. mamane+SAHAall","B. mamane+SAHAprod","Untreated B. mamane","B. mamane+VSall","B. mamane+VSprod"), 
       intensity = c(770606573.5, 
           613182573.3, 
           780913983.6, 
           829523587.7, 
           809287616.6)) 

作りプロット

p <-ggplot(data, aes(group, y=intensity)) + 
geom_bar(stat="identity", aes(fill =group))+theme(legend.position = "none") 
theme_minimal()+ 
theme(axis.title.x=element_blank(), 
axis.text.x=element_blank(), 
axis.ticks.x=element_blank()) 

     p1 <-ggplot(data1, aes(group, y=intensity)) + 
    geom_bar(stat="identity", aes(fill =group))+ 
    theme_minimal()+ 
    theme(axis.title.x=element_blank(), 
     axis.text.x=element_blank(), 
     axis.ticks.x=element_blank()) 
    p2 <-ggplot(data2, aes(group, y=intensity)) + 
    geom_bar(stat="identity", aes(fill =group))+ 
    theme_minimal()+ 
    theme(axis.title.x=element_blank(), 
      axis.text.x=element_blank(), 
     axis.ticks.x=element_blank()) 
    p3 <-ggplot(data3, aes(group, y=intensity)) + 
    geom_bar(stat="identity", aes(fill =group))+ 
    theme_minimal()+ 
    theme(axis.title.x=element_blank(), 
     axis.text.x=element_blank(), 
     axis.ticks.x=element_blank()) 
    p4 <-ggplot(data4, aes(group, y=intensity)) + 
    geom_bar(stat="identity", aes(fill =group))+ 
    theme_minimal()+ 
    theme(axis.title.x=element_blank(), 
     axis.text.x=element_blank(), 
     axis.ticks.x=element_blank()) 
    library(grid) 
plot_grid(p,p1,p2,p3,p4, labels=c("A", "B","C","D","E"), ncol = 2, nrow = 3) 

答えて

1
data0 <- data 

library(plyr) 
all<- ldply(0:4, function(x){ 
      tmp <- get(paste0("data", x)) 
      tmp$gp <- x 
      tmp 
     }) 

ggplot(all, aes(group, intensity, fill=group)) + 
    geom_bar(stat="identity", aes(fill =group)) + 
    geom_errorbar(data=all[all$gp==0, ], aes(
       ymin=intensity-sd, ymax=intensity+sd)) + 
    facet_wrap(~gp, scales="free", ncol=2) + 
    theme_minimal()+ 
    theme(legend.position = "bottom", 
     axis.title.x=element_blank(), 
     axis.text.x=element_blank(), 
     axis.ticks.x=element_blank(), 
     strip.background = element_blank(), 
     strip.text.x = element_blank()) 

enter image description here

+1

アダムありがとう。エラーバーを小さくするには? – Asih

+1

'geom_errobar'関数に' width = .1'を追加してください。 [手段とエラーバーをプロットする](http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/)に詳しい –

関連する問題