Skip to content

Instantly share code, notes, and snippets.

@BB1464
Created July 9, 2022 07:39
Show Gist options
  • Save BB1464/8af9031a81ed03fd62c684ed6085a1f8 to your computer and use it in GitHub Desktop.
Save BB1464/8af9031a81ed03fd62c684ed6085a1f8 to your computer and use it in GitHub Desktop.
My demo on GeoSpatial Analysis in R
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