캡션을 수정하려고하는데 만드는 데 문제가 있습니다. 클래스 (채우기), 모양 제한 (색상), 점 (색상) 및 그리드 (채우기 = NA)에 대한 캡션을 원했습니다. 모두 넣었 aes ()
지만 예상 한 결과가 없습니다. 아무도 나를 도울 수 있습니까? 감사!
library(geobr)
library(sf)
library(ggplot2)
library(ggspatial)
#Directory
getwd()
#Download spatial data ------------------------------------------------
download.file(url = "http://geo.fbds.org.br/SP/RIO_CLARO/USO/SP_3543907_USO.dbf",
destfile = "SP_3543907_USO.dbf", mode = "wb")
download.file(url = "http://geo.fbds.org.br/SP/RIO_CLARO/USO/SP_3543907_USO.prj",
destfile = "SP_3543907_USO.prj", mode = "wb")
download.file(url = "http://geo.fbds.org.br/SP/RIO_CLARO/USO/SP_3543907_USO.shp",
destfile = "SP_3543907_USO.shp", mode = "wb")
download.file(url = "http://geo.fbds.org.br/SP/RIO_CLARO/USO/SP_3543907_USO.shx",
destfile = "SP_3543907_USO.shx", mode = "wb")
#Import spatial data --------------------------------------------------
uso <- sf::st_read("SP_3543907_USO.shp")
uso
plot(uso$geometry)
#Area limit
rio_claro_limit <- geobr::read_municipality(code_muni = 3543907, year = 2015)
rio_claro_limit
plot(rio_claro_limit$geom)
#Random sample points
set.seed(123)
pts <- st_sample(uso, size = 20, type="random") %>% st_sf
#Grid 50km x 50km
grid_50 <- st_make_grid(uso, cellsize = c(5000, 5000)) %>%
st_sf(grid_id = 1:length(.))
#Labels grid
grid_lab <- st_centroid(grid_50) %>% cbind(st_coordinates(.))
#Points in grid
pts %>% st_join(grid_50, join = st_intersects) %>% as.data.frame
#Map --------------------------------------------------------------------
ggplot() +
geom_sf(data = uso, aes(fill = CLASSE_USO, color = NA)) +
geom_sf(data = rio_claro_limit, aes(color = 'black', fill = NA)) +
geom_sf(data = pts, aes(color = 'red'), size = 1.7) +
geom_sf(data = grid_50, aes(fill=NA), lwd = 0.3) +
geom_text(data = grid_lab, aes(x = X, y = Y, label = grid_id), size = 2) +
xlab("")+
ylab("")+
scale_fill_manual(name="Classes de Uso", values = c("blue", "orange", "gray30", "forestgreen", "green", NA))+
scale_color_identity(guide = "legend")
다음과 같이 원하는 결과를 얻을 수 있습니다.
나는 모든 이동 fill=NA
과 color=NA
의 밖으로 aes()
문. 평소와 같이 특정 값에 대한 색상을 수정하거나 채우기 또는 더 일반적으로 모든 aes를 원하는 경우 범례에 표시하려는 경우를 제외하고는 aes () 외부에 두는 것이 가장 좋습니다.
key_glyph
"포인트"레이어의 소위 , 즉 범례에 그려진 아이콘을로 설정합니다 "point"
.
이 단계는 채우기 키 주위의 검은 색 테두리도 제거함에 따라 guides
레이어를 추가하여 다시 가져 왔습니다. 개인적으로 나는 검은 색 테두리를 제거 할 것이지만, 당신의 음모입니다. (:
library(geobr)
library(sf)
library(ggplot2)
library(ggspatial)
ggplot() +
geom_sf(data = uso, aes(fill = CLASSE_USO), color = NA) +
geom_sf(data = rio_claro_limit, aes(color = 'black'), fill = NA, key_glyph = "point") +
geom_sf(data = pts, aes(color = 'red'), size = 1.7, key_glyph = "point") +
geom_sf(data = grid_50, fill = NA, lwd = 0.3) +
geom_text(data = grid_lab, aes(x = X, y = Y, label = grid_id), size = 2) +
xlab("")+
ylab("")+
scale_fill_manual(name="Classes de Uso", values = c("blue", "orange", "gray30", "forestgreen", "green", NA)) +
guides(fill = guide_legend(override.aes = list(color = "black"))) +
scale_color_identity(guide = "legend")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다