我正在尝试构建一个自定义函数来向绘图窗口添加点。我的问题是,当我使用jitter
时,图的左右部分的分布似乎不同。
为什么是这样 ?
set.seed(8)
f1 <- function(x, y, col = 'black', xjit = 5, ...) {
points(x = jitter(rep(x, length(y)), xjit), y = y, col = col, ...)
}
v <- sample(1:1000, 1000, T) #Some data to plot
ymax <- max(v)
plot.new() #Build a canvas from scratch
plot.window( xlim = c(1, 10), ylim = c(0, ymax) )
ticks <- seq(1, 10, 1)
axis(1, at=ticks, labels=NA)
axis(2)
#Plot the same data to the left (x=1) and right (x=10)
f1(1, v, 'red', pch = 4)
f1(10, v, 'blue', pch = 4)