2016-12-05 7 views
0

Rでは、特定のx軸のプロットに平均を追加する手段がありますか? 「で」特定のX軸でRをプロットする

plot(1, 1, xlim = c(0, 6.5), ylim = c(0,300), type = 'n', xlab = '', ylab = '', xaxt = 'n') #xaxs="i",yaxs="i") 
boxplot(dataset,at = 0.5, add = T, range = 6,yaxt = 'n') 
points(mean(dataset), at = 0.5, add = T) 

私が言ってメッセージを取得している「ではないグラフィカルなパラメータ」を「追加」:例えば、私のような何かをしたいです。回避策はありますか?

私はRStudioを使用しています。 11個の数字を持つ6つの異なる値(data_a、data_b、data_c、data_d、data_e、およびdata_f)があります。現在のコードは次のようになります:

par(xpd = FALSE) 
par(mar=c(8,4.5,2,1)) 
plot(1, 1, xlim = c(0, 6.5), ylim = c(0,300), type = 'n', xlab = '', ylab = '', xaxt = 'n') #xaxs="i",yaxs="i") 
boxplot(data_a,at = 0.5, add = T, range = 6,yaxt = 'n') 
boxplot(data_b,at = 1.5, add = T, range = 6,yaxt = 'n') 
boxplot(data_c,at = 2.5, add = T, range = 6,yaxt = 'n') 
boxplot(data_d,at = 4, add = T, range = 6,yaxt = 'n') 
boxplot(data_e,at = 5, add = T, range = 6,yaxt = 'n') 
boxplot(data_f,at = 6, add = T, range = 6,yaxt = 'n') 
axis(2, at = 150, pos = -0.65, tck = 0, labels = 'X axis label',cex.axis=1.1) 
axis(1, at = c(0.5,1.5,2.5,4,5,6),labels=c('','','','','','')) 
axis(1, at = c(1.5,5),pos= -25,labels=c('label 1','labe 2'),tick=FALSE) 
axis(1, at = c(3.25),labels=c(''),tck=-0.15) 
axis(1, at = c(3.25),pos = -50,labels=c('Y axis label'),tick=FALSE) 
abline(v=3.25) 
par(xpd = NA) 
text(0.5,-30, expression("a)) 
text(1.5,-30, expression("b")) 
text(2.5,-30,"c") 
text(4,-30, expression(d)) 
text(5,-30, expression("e")) 
text(6,-30,"f") 

今、私は平均を追加できます。

+0

あなたは、SAMを追加することができますプレデータセット –

答えて

1

あなたは、ランダムに生成DATA_Aで(希望のプロットを得るために、これを試すことができますDATA_Bなど):

par(xpd = FALSE) 
par(mar=c(8,4.5,2,1)) 
plot(1, 1, xlim = c(0, 6.5), ylim = c(0,300), type = 'n', xlab = '', ylab = '', xaxt = 'n') #xaxs="i",yaxs="i") 
data_a <- runif(11, 0, 300) 
data_b <- runif(11, 0, 300) 
data_c <- runif(11, 0, 300) 
data_d <- runif(11, 0, 300) 
data_e <- runif(11, 0, 300) 
data_f <- runif(11, 0, 300) 
boxplot(data_a,at = 0.5, add = T, range = 6,yaxt = 'n') 
boxplot(data_b,at = 1.5, add = T, range = 6,yaxt = 'n') 
boxplot(data_c,at = 2.5, add = T, range = 6,yaxt = 'n') 
boxplot(data_d,at = 4, add = T, range = 6,yaxt = 'n') 
boxplot(data_e,at = 5, add = T, range = 6,yaxt = 'n') 
boxplot(data_f,at = 6, add = T, range = 6,yaxt = 'n') 
axis(2, at = 150, pos = -0.65, tck = 0, labels = 'X axis label',cex.axis=1.1) 
axis(1, at = c(0.5,1.5,2.5,4,5,6),labels=c('','','','','','')) 
axis(1, at = c(1.5,5),pos= -25,labels=c('label 1','label 2'),tick=FALSE) 
axis(1, at = c(3.25),labels=c(''),tck=-0.15) 
axis(1, at = c(3.25),pos = -50,labels=c('Y axis label'),tick=FALSE) 
abline(v=3.25) 
par(xpd = NA) 
text(0.5,-30, expression("a")) 
         text(1.5,-30, expression("b")) 
         text(2.5,-30,"c") 
         text(4,-30, expression("d")) 
         text(5,-30, expression("e")) 
         text(6,-30,"f") 
points(c(0.5,1.5,2.5,4,5,6), c(mean(data_a), mean(data_b), mean(data_c), mean(data_d), mean(data_e), mean(data_f)), pch = 22, col = "darkgrey", lwd = 7) 

enter image description here

1

ボックスプロットでは、x軸のプロットの位置は単位(1、2、3など)です。これを確認するには、locator()ファンクションを使用します。ここで

アイリスデータセットを使用して、箱ひげ図の赤い丸のような手段を追加する例です。

boxplot(Sepal.Length ~ Species, data = iris) 
points(seq_along(levels(iris$Species)), with(iris, tapply(Sepal.Length, Species, mean)), col = "red") 

enter image description here

関連する問題