小编Dav*_*ske的帖子

使用相同的facet数据向每个facet_wrap添加子图

我尝试根据与相应facet_wrap 图中相同的数据,将直方图splot 添加到facet_wrap 图的每个部分geom_sf 图。

我通过谷歌找到了一些方法,但到目前为止还没有具体的方法。

我之前的做法:

library(sf)
library(ggplot2)

nc <- st_read(system.file("shape/nc.shp", package="sf"))
nc <- rbind(nc, nc[rep(1:100, 3), ])
nc <- nc[order(nc$NAME),]
nc$GROUP <- c("A", "B", "C", "D")
nc$VALUE <- runif(400, min=0, max=10)

main <- ggplot() +
  geom_sf(data = nc,
          aes(fill = VALUE),
          color = NA) +
  scale_fill_gradientn(colours = c("#f3ff2c", "#96ffea", "#00429d"),
                       guide = "colorbar") +
  coord_sf(datum = NA) +
  theme(panel.background = element_blank(),
        strip.background = element_blank(),) +
  facet_wrap(~ GROUP, nrow = 2)

sub <- ggplot(nc, aes(x=VALUE)) + 
  geom_histogram(binwidth = 1) …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 facet-wrap subplot

4
推荐指数
1
解决办法
579
查看次数

标签 统计

facet-wrap ×1

ggplot2 ×1

r ×1

subplot ×1