【发布时间】:2022-01-05 17:28:55
【问题描述】:
我试图在 ggplot2 中绘制一个圆形的 7 个点的图形,但尝试绘制它们只显示 6 个,我不知道为什么会发生这种情况。
代码如下:
# Function for the points
circleFun <- function(center = c(-1, 1), diameter = 1, npoints = 7) {
r <- diameter / 2
tt <- seq(0, 2 * pi, length.out = npoints)
xx <- center[1] + r * cos(tt)
yy <- center[2] + r * sin(tt)
return(data.frame(x = xx, y = yy))
}
# example with 7 points
ej <-
circleFun(diameter = 50, center = c(50,50), npoints = 7)
# plot
ej |>
ggplot(aes(x = x, y = y)) +
geom_point(alpha = 0.4) +
theme_bw()
有人知道为什么会这样吗?
【问题讨论】:
-
第 1 行和第 7 行是相同的,所以它们的点是重叠的。这个点有点暗(根据你的
alpha = 0.4)。您可以通过添加x = jitter(x)来使这一点变得明显(为了演示,您不会在生产中这样做)。鉴于相同的数据,我不确定您希望看到什么。