library(raster)
library(ggplot2)
library(sf)
temp.shp <- getData('GADM', country='FRA', level = 2)
temp.shp <- st_as_sf(temp.shp)
dat <- data.frame(CC_2 = rep(temp.shp$CC_2, times = 3),
value = c(sample(1:100, length(temp.shp$CC_2), replace = T),
sample(0.1:1, length(temp.shp$CC_2), replace = T),
sample(-1:-100, length(temp.shp$CC_2), replace = T)),
client = rep(c('a','b','c'), each = length(temp.shp$CC_2)))
dat.shp <- merge(temp.shp, dat, by = 'CC_2')
ggplot() +
geom_sf(data = dat.shp, aes(fill = value), colour = NA) +
scale_fill_viridis_c(option = 'C') +
facet_wrap(~client)
범례 범위가 다르기 때문에 각 패널에 고유 한 범례가 있기를 원합니다.
ggplot() +
geom_sf(data = dat.shp, aes(fill = value), colour = NA) +
scale_fill_viridis_c(option = 'C') +
facet_wrap(~client, scales = 'free')
# Error: coord_sf doesn't support free scales
tmap
패키지 사용을 고려할 수도 있습니다 . 가능한 해결책은 다음과 같습니다.
library(raster)
library(ggplot2)
library(sf)
library(tmap)
temp.shp <- getData('GADM', country='FRA', level = 2)
temp.shp <- st_as_sf(temp.shp)
dat <- data.frame(CC_2 = rep(temp.shp$CC_2, times = 3),
value = c(sample(1:100, length(temp.shp$CC_2), replace = T),
sample(0.1:1, length(temp.shp$CC_2), replace = T),
sample(-1:-100, length(temp.shp$CC_2), replace = T)),
client = rep(c('a','b','c'), each = length(temp.shp$CC_2)))
dat.shp <- merge(temp.shp, dat, by = 'CC_2')
tm_shape(dat.shp) +
tm_polygons("value", palette = "viridis") +
tm_layout(legend.position = c("left", "bottom")) +
tm_facets("client", free.scales = TRUE)
reprex 패키지 (v0.3.0)에 의해 2020-03-12에 생성됨
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다