简体   繁体   English

R:绘制点时控制抖动-在分类X轴上获得不均等的扩散

[英]R: control jitter when plotting with points - get unequal spread on categorial x-axis

I am trying to build a custom function to add points to a plot window. 我试图建立一个自定义函数以将点添加到绘图窗口。 My problem is that when I use jitter it seems that the spread is different in the right vs left part of the plot. 我的问题是,当我使用jitter时,图的左右部分的展jitter似乎有所不同。

Why is this ? 为什么是这样 ?

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)

数字

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM