1

我正在修改我之前在 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 个圆圈然后是前十个圆圈来编写解决方法,但它并不优雅

4

2 回答 2

0

这是一个错误ggforce:它将圆圈中的点用与原始圆圈排序不同的字符串分组。

要获得修复错误的版本,请使用

remotes::install_github("dmurdoch/ggforce@sortorder")

这将要求您安装包构建工具。如果您没有这些,您可以查看网站https://github.com/thomasp85/ggforce/issues/224以查看修复程序何时合并到包的 CRAN 构建中。

于 2021-02-28T15:51:48.060 回答
0

我只能提供一个稍微笨拙的解决方法,它对于大型数据集可能效果不佳。循环遍历每一行,创建一个圆圈,然后将它们全部加在一起以制作一个要绘制的对象。

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

在此处输入图像描述

于 2021-02-28T13:42:46.943 回答