2

ggplot2 を使用して、一連のデータ (Y の $ proteinN および X の $ メソッド) から SDM を使用して棒グラフを作成し、同じ棒グラフ (重複) に凡例の別のデータ セット ($ 固有) のインジケーターを含めたいと思います。ブレット棒グラフの形をしています。これに少し似ています(ただし、最初のデータセットの垂直バーとSDM)


(ソース: yaksis.com )

ここに私のコードとデータがあります:

    library(ggplot2) 
    data <- textConnection("proteinN, supp, method, specific
    293, protnumb, insol, 46
    259, protnumb, insol, 46
    274, protnumb, insol, 46
    359, protnumb, fasp, 49
    373, protnumb, fasp, 49
    388, protnumb, fasp, 49
    373, protnumb, efasp, 62
    384, protnumb, efasp, 62
    382, protnumb, efasp, 62
    ")

    data <- read.csv(data, h=T)

# create functions to get the lower and upper bounds of the error bars
stderr <- function(x){sqrt(var(x,na.rm=TRUE)/length(na.omit(x)))}
lowsd <- function(x){return(mean(x)-stderr(x))}
highsd <- function(x){return(mean(x)+stderr(x))}

cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", 
               "#F0E442", "#0072B2", "#D55E00", "#CC79A7")

# create a ggplot
ggplot(data=data,aes(x=method, y=proteinN, fill=method))+
  #Change _hue by _manualand remove c=45, l=80 if not desire#
  scale_fill_manual(values=cbPalette)+
  scale_fill_hue(c=45, l=80)+

  # first layer is barplot with means
  stat_summary(fun.y=mean, geom="bar", position="dodge", colour='black')+
  # second layer overlays the error bars using the functions defined above
  stat_summary(fun.y=mean, fun.ymin=lowsd, fun.ymax=highsd, 
              geom="errorbar", position="dodge",color = 'black', size=.5)

私はいくつかのことを試しましたが、何もうまくいきません.2番目のデータセットを追加しようとすると、常にこのエラー出力が得られました:

エラー : 変数を y にマップし、さらに stat="bin" を使用しています。stat="bin" を使用すると、y 値を各グループのケース数に設定しようとします。これは予期しない動作を引き起こす可能性があり、ggplot2 の将来のバージョンでは許可されません。y でケース数を表す場合は、stat="bin" を使用し、変数を y にマップしないでください。y でデータの値を表す場合は、stat="identity" を使用します。例については、?geom_bar を参照してください。(廃止; 最後に使用されたのはバージョン 0.9.2)

エラー : 変数を y にマップし、さらに stat="bin" を使用しています。stat="bin" を使用すると、y 値を各グループのケース数に設定しようとします。これは予期しない動作を引き起こす可能性があり、ggplot2 の将来のバージョンでは許可されません。y でケース数を表す場合は、stat="bin" を使用し、変数を y にマップしないでください。y でデータの値を表す場合は、stat="identity" を使用します。例については、?geom_bar を参照してください。(廃止; 最後に使用されたのはバージョン 0.9.2)

これが私の試みです:

# create functions to get the lower and upper bounds of the error bars
stderr <- function(x){sqrt(var(x,na.rm=TRUE)/length(na.omit(x)))}
lowsd <- function(x){return(mean(x)-stderr(x))}
highsd <- function(x){return(mean(x)+stderr(x))}

cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", 
               "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
# create a ggplot
ggplot(data=data,aes(x=method, y=proteinN, fill=method, witdh=1))+
  #Change _hue by _manualand remove c=45, l=80 if not desire#
  scale_fill_manual(values=cbPalette)+
  scale_fill_hue(c=45, l=80)+

  #Second set of data#
  geom_bar(aes(x=method, y=specific, fill="light green"), width=.4) +

  # first layer is barplot with means
  stat_summary(fun.y=mean, geom="bar", position="dodge", colour='black')+

  # second layer overlays the error bars using the functions defined above
  stat_summary(fun.y=mean, fun.ymin=lowsd, fun.ymax=highsd, 
      geom="errorbar", position="dodge",color = 'black', size=.5)
4

1 に答える 1