我尝试根据与相应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)