問題がbarplot
はx軸上の整数値を使用しないことです。それは独自のx値を計算します、私はスケーリングのために推測します。使用している点のベクトルを取得して他のものと整列させるには、barplot
の呼び出しで返されたオブジェクトからそれらを引き出す必要があります。ここでは例です:私はポイント(またはライン)の余地があったことを確認するbarplot
への最初の呼び出しでylim
を設定する必要がありました
# make some toy data
set.seed(1)
df <- data.frame(cat = LETTERS[1:3],
val = seq(3),
val2 = rpois(3, lambda = 5),
stringsAsFactors = FALSE)
# now try adding val2 as points to a barplot of val1; as you found, the
# points aren't centered
# over the bars like we want
barplot(df$val, ylim = c(0,7))
points(x = seq(3), y = df$val2, pch = 20, col = "red")
# try again, this time capturing the x values from a call to barplot and then
# using them in the call to points; this works
p <- barplot(df$val, ylim = c(0,7))
points(x = p, y = df$val2, pch = 20, col = "red")
注意。
また、 'vec2 < - cumsum(vec1)'を試してください。 – coffeinjunky
ねえ..ありがとう。問題は依然として、プロットまたはラインのx軸が、バープロット(すなわち、バーの中央にない)と整列していないことである。 – Amir
出力がこれに由来するものであることが分かると便利です。 – Graham