2017-04-16 23 views
1

エラーバーの折れ線グラフが必要です。折れ線グラフとエラーバー

私は次のようにデータを持っている:

data <- read.table(text = "servers Throughput Error Protocols 
3 3400 3.45 Z1 
5 2300 3.45 Z1 
7 1700 3.45 Z1 
9 1290 3.45 Z1 
3 5000 1.064564 Z2 
5 2500 1.064564 Z2 
7 1800 1.064564 Z2 
9 1400 1.064564 Z2 
3 4500 1.064564 Z3 
5 2490 1.064564 Z3 
7 1780 1.064564 Z3 
9 1370 1.064564 Z3", header = TRUE) 

を次のように折れ線グラフとエラーバーを描画するためのスクリプト:

data$servers <- as.factor(data$servers) 

plot1 <- ggplot(data=data , aes(x=servers, y=Throughput, group=Protocols, colour = Protocols, shape=Protocols)) + 
    geom_errorbar(aes(plot1,ymin=Throughput-Error, ymax=Throughput+Error) + 
    geom_line() + 
    geom_point(size=3) 

plot1 <- plot1 + scale_y_continuous(breaks= seq(0,5500,500), limits = c(0,5500)) + 
    labs(x="size") + 
    scale_x_continuous(breaks = c(3, 5, 7,9)) + 
    labs(y="Throughput (ops/sec)") 

plot1 <- plot1 + scale_colour_manual(values=c("#66CC99","#997300", "#6c3483")) 

plot1 <- plot1 + theme_bw() + 
    theme(legend.position="bottom") + 
    labs(fill="", colour=" ", shape=" ") + 
    theme(text = element_text(size=18)) + 
    guides(fill = guide_legend(keywidth = 0.8, keyheight = 0.01)) 

plot1 

問題はエラーバーが表示されないということです。

助けが必要ですか?

答えて

0

あなたのコードには、私が気づいて修正したいくつかのエラーがありました。あなたが変更した場合はその下にあなたのgeom_errorbar呼び出しはエラーバーを修正する必要があります。

geom_errorbar(aes(ymin=Throughput-Error, ymax=Throughput+Error)) 

はまた、あなたのコードの1行目に、あなたが要因であるとdata$serversを変更します。これを要素とすることはできません。scale_x_continuous - data$serversを数値に設定するか、scale_x_discreteを使用する必要があります。私はちょうどdata$serversを数値のままにしたかった。

このコードは動作するはずです:

plot1 <- ggplot(data=data , aes(x=servers, y=Throughput, group=Protocols, colour = Protocols, shape=Protocols)) + 
       geom_errorbar(aes(ymin=Throughput-Error, ymax=Throughput+Error)) + 
       geom_line() + 
       geom_point(size=3) 

      plot1 <- plot1 + scale_y_continuous(breaks= seq(0,5500,500), limits = c(0,5500)) + 
      labs(x="size") + 
      scale_x_continuous(breaks = c(3, 5, 7,9)) + 
      labs(y="Throughput (ops/sec)") 

      plot1 <- plot1 + scale_colour_manual(values=c("#66CC99","#997300", "#6c3483")) 

      plot1 <- plot1 + theme_bw() + 
      theme(legend.position="bottom") + 
      labs(fill="", colour=" ", shape=" ") + 
      theme(text = element_text(size=18)) + 
      guides(fill = guide_legend(keywidth = 0.8, keyheight = 0.01)) 

      plot1 

enter image description here

編集: 垂直値は非常に小さいので、あなたのエラーバーが水平になるように見える理由はあります。エラーバーのy値は、data$Throughputからdata$Errorを加算/減算しています。 data$Throughputが2000で、3.5を加算/減算すると(これは約data$Error)、垂直バーは表示されません。

あなたのError列の尺度は何ですか?

enter image description here

+0

グッド試してみてください。ここでは300でdata$Errorを掛ける同じプロットです。しかし、エラーバーを垂直にする方法は? Becuase Error barはx軸ではなくy軸に関連しています@Mike –

+0

これらは垂直です...実際のスループット値の一部を加算/減算するだけです。あなたの 'data $ Error'に100を掛けてみてください。 –

+0

それはうまくいかないのですか? @Mike H –

関連する問題