我正在修改我在Limited number of geoms in ggforce?上发布的一个问题。我当时认为我错了,但现在我可以更清楚地重建它:我想把N个圆圈一个放在另一个的上面。无论我想绘制多少个圆,圆#11-N都绘制在前10个圆的下面。这演示了问题的起因:
library(tidyverse)
library(ggforce)
circles <- data.frame(
x0 = seq(1, 30),
y0 = seq(1, 30),
r = 2
)
ggplot() +
geom_circle(aes(x0 = x0, y0 = y0, r = r), fill = "grey", data = circles) +
coord_fixed()因此,当我想绘制同心圆时,前10个圆隐藏了所有其余的圆。我可以编写一个解决方法,首先绘制11-N个圆,然后绘制前10个圆,但这并不优雅
发布于 2021-02-28 23:51:48
这是ggforce中的一个错误:它使用字符串对圆中的点进行分组,这些字符串与原始圆的排序顺序不同。
要获得修复该错误的版本,请使用
remotes::install_github("dmurdoch/ggforce@sortorder")这将要求您安装包构建工具。如果你没有这些补丁,你可以查看网站https://github.com/thomasp85/ggforce/issues/224,看看补丁什么时候被整合到这个包的CRAN版本中。
发布于 2021-02-28 21:42:47
我只能提供一个稍微有点老生常谈的解决办法,它在大型数据集上的表现可能不是很好。循环遍历每一行,创建一个圆圈,然后将它们全部相加,形成一个要绘制的对象。
library(tidyverse)
library(ggforce)
circles <- data.frame(
x0 = seq(1, 30),
y0 = seq(1, 30),
r = 2
)
mygeom_circle <- function(onerow) {
geom_circle(aes(x0 = x0, y0 = y0, r = r), fill = "grey", data = onerow)
}
gs <- sapply(1:nrow(circles), function(r) mygeom_circle(circles[r,])) # loop through one by one making single circles
gg <-
ggplot() +
gs + # add the single circles in the order they were made
coord_fixed()
gg

https://stackoverflow.com/questions/66408402
复制相似问题