3

次のベクトルを検討してください。

  q1 <- c(1000000.0,  908364.8,  876009.1,  847892.8,  824808.3,  805416.2,  785266.2, 770997.1,  753908.6,  744599.9,  706777.6,  674659.9,  634654.4,  601440.4, 568259.7,  535361.3,  493679.9,  465526.5,  429766.6,  395244.7,  361483.2, 332136.6, 308574.5, 285500.6, 262166.2 ,237989.0 , 210766.1,  188578.1, 166762.3 , 140399.8  ,114865.5)

プロットは次のとおりです。

 dev.new(width=10, height=5)
 par(xaxs='i',yaxs='i')
 plot(q1, type = "l", lty = 1, lwd = 2, col = "green", xaxt = 'n', xlim = c(0,30), bty = "l")
 x.ticks = seq(from = 0, to = 30, by = 5)
 axis(1, at = x.ticks+1,  labels=paste("Year", x.ticks, sep=" "))

ここに画像の説明を入力

何らかの理由で、x 軸と y 軸が (0,0) で交わっていません! を使用してこれを修正しようとしpar(xaxs='i',yaxs='i')ましたが、この場合はうまくいきませんか?

何か案は?ありがとう!

4

1 に答える 1

4

ylim を指定しない場合、R はプロット領域をデータに合わせますが、プロットを原点まで拡張しません。これで修正されます:

plot(q1, type = "l", lty = 1, lwd = 2, col = "green", xaxt = 'n', 
     xlim = c(0,30), ylim = c(0, max(q1,  na.rm = TRUE)), bty = "l")

q1 の最大値を探すために ylim を書きました。固定値に変更できます。

これを機能させるために実行した完全なコードは次のとおりです。

q1 <- c(1000000.0,  908364.8,  876009.1,  847892.8,  824808.3,  805416.2,  
        785266.2, 770997.1,  753908.6,  744599.9,  706777.6,  674659.9,  
        634654.4,  601440.4, 568259.7,  535361.3,  493679.9,  465526.5,  
        429766.6,  395244.7,  361483.2, 332136.6, 308574.5, 285500.6, 
        262166.2 ,237989.0 , 210766.1,  188578.1, 166762.3 , 140399.8  ,114865.5)

dev.new(width=10, height=5)
par(xaxs='i',yaxs='i')
plot(q1, type = "l", lty = 1, lwd = 2, col = "green", 
     xaxt = 'n', xlim = c(1,30), ylim = c(0, max(q1)), bty = "l")
x.ticks = seq(from = 0, to = 30, by = 5)
axis(1, at = x.ticks + 1,  labels=paste("Year", x.ticks, sep=" "))
于 2013-10-21T19:40:37.900 に答える