0

我正在尝试构建一个自定义函数来向绘图窗口添加点。我的问题是,当我使用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)

数字

4

1 回答 1

0

抖动是输入变量的函数,因此只需在使用 f1 函数中的相同第一个变量计算后将抖动结果添加到原始数字。

于 2018-05-25T19:15:41.737 回答