Created
July 9, 2022 07:39
-
-
Save BB1464/8af9031a81ed03fd62c684ed6085a1f8 to your computer and use it in GitHub Desktop.
My demo on GeoSpatial Analysis in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rnaturalearthdata) | |
library(sf) | |
library(ggthemes) | |
country_sf <- countries110 %>% | |
st_as_sf() | |
ggplot() + | |
geom_sf(data = country_sf, | |
aes(fill = lastcensus, | |
shape = "No data\navailable")) + | |
scale_fill_viridis_c() | |
# Nicer version of chart | |
ggplot() + | |
geom_sf(data = country_sf, | |
aes(fill = lastcensus, | |
shape = "No data\navailable"), | |
colour = "white", | |
size = 0.2) + | |
scale_fill_viridis_c(na.value = "pink") + | |
guides(shape = guide_legend(override.aes = list(fill = "pink"), | |
order = 2, | |
title = NULL), | |
fill = guide_colorbar(order = 1)) + | |
theme_void() + | |
theme(legend.margin = margin(r = 5))+coord_sf(crs = 4326,expand = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment