2017-03-02 55 views
0

我有以下代碼:箱圖中R.Ý間隔(刻度線)和電網

boxplot(c(Scatt_nocoop, Scatt_coop), 
      xlab="Scattered", col=c("red","red"), 
      names=c("Non-cooperative"," Cooperative "), 
      ylim = c(0,2.5)) 

我試圖添加刻度標記在Y軸每0.1,以再加入一個網格。

此外,我想獲得Y軸的百分比而不是數字。

謝謝!

回答

1

不知道你的數據看起來像什麼,但我想你想是這樣的:

x1 <- rnorm(100) + 2 

x2 <- rnorm(100) + 2 

df <- data.frame(x = c(x1, x2), g = rep(1:2,each=100)) 

boxplot(df$x~df$g, 
     xlab="Scattered", col=c("red","red"), 
     names=c("Non-cooperative"," Cooperative "), 
     ylim = c(0,5), 
     yaxt = "n") 

添加蜱(手動)網格線

axis(2, at = seq(0,5,0.1)) 
lapply(seq(0,5,0.1), function(x) abline(a = x,b = 0)) 
+0

太感謝你了!我怎麼能把這些數字放在Y軸上作爲1,2,3,4的顯示?謝謝! – Pabs88

+1

在函數'axis'中使用參數'標籤'。例如:'axis(2,at = seq(0,5,0.1),labels = paste(seq(0,5,0.1),'%'),las = 1)' – Wietze314

+0

謝謝!這很有用! – Pabs88