让我们以显示图像而不是 ggplot 上的点为例。
set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
y = rnorm(10),
image = sample(c("https://www.r-project.org/logo/Rlogo.png",
"https://jeroenooms.github.io/images/frink.png"),
size=10, replace = TRUE)
)
# plot2
ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.08)
我需要修改代码,以便在图像重叠(或基于 x,y 彼此更接近)时添加一些距离/抖动。如果没有太复杂的解决方法,这可能吗?
尝试
position = position_jitter()
:
(如果需要,您可以在
seed
中设置 position_jitter
以提高重现性。)
library(ggplot)
library(ggimage)
set.seed(2)
d <- data.frame(
x = rnorm(10),
y = rnorm(10),
image = sample(
c(
"https://www.r-project.org/logo/Rlogo.png",
"https://jeroenooms.github.io/images/frink.png"
),
size = 10,
replace = TRUE
)
)
ggplot(d, aes(x, y)) +
geom_image(aes(image = image), size = .08, position = position_jitter(width = 0.2))