Code
library(pacman)
pacman::p_load(tidyverse, sf, dplyr, rnaturalearth, showtext, ragg, glue)
showtext_auto()Ana Luisa Bodevan
# get south america polygon
sa <- ne_countries(continent = "South America", returnclass = "sf") |>
st_union() |> # single polygon
st_transform(3857) # project to meters for equal grid spacing
# create a regular grid of points
grid_spacing <- 60000 # in meters; smaller = denser grid
grid <- st_make_grid(sa,
what = "centers",
cellsize = grid_spacing) |>
st_as_sf() |>
st_intersection(sa) # keep only points inside polygonggplot() +
geom_sf(data = grid, aes(color = y), size = 0.8, show.legend = FALSE) +
scale_color_gradientn(colors = golden_palette) +
coord_sf(expand = FALSE, clip = "off") +
theme_void() +
theme(
plot.background = element_rect(fill = "white", color = NA),
plot.margin = margin(t = 0, # Top margin
r = 1, # Right margin
b = 0, # Bottom margin
l = 1, # Left margin
unit = "cm")) 
Last few tweaks made on Canva

---
title: "Points"
author: "Ana Luisa Bodevan"
description: "South America in Points"
image: "01_points.png"
execute:
warning: false
message: false
eval: true
format:
html:
code-tools: true
code-fold: true
---
# Day 1: Points
| Challenge Classic: Map with point data (e.g., individual locations, points of interest, clusters). Focus on effective symbolization and density visualization.
### Loading libraries
```{r}
library(pacman)
pacman::p_load(tidyverse, sf, dplyr, rnaturalearth, showtext, ragg, glue)
showtext_auto()
```
### Loading and preparing data
```{r}
# get south america polygon
sa <- ne_countries(continent = "South America", returnclass = "sf") |>
st_union() |> # single polygon
st_transform(3857) # project to meters for equal grid spacing
# create a regular grid of points
grid_spacing <- 60000 # in meters; smaller = denser grid
grid <- st_make_grid(sa,
what = "centers",
cellsize = grid_spacing) |>
st_as_sf() |>
st_intersection(sa) # keep only points inside polygon
```
### Colors
```{r}
# color pallete
set.seed(123)
golden_palette <- c("#F9C74F", "#F8961E", "#F3722C", "#F9844A")
grid$color <- sample(golden_palette, nrow(grid), replace = TRUE)
grid$y <- st_coordinates(grid)[, 2]
```
### Plot
```{r}
ggplot() +
geom_sf(data = grid, aes(color = y), size = 0.8, show.legend = FALSE) +
scale_color_gradientn(colors = golden_palette) +
coord_sf(expand = FALSE, clip = "off") +
theme_void() +
theme(
plot.background = element_rect(fill = "white", color = NA),
plot.margin = margin(t = 0, # Top margin
r = 1, # Right margin
b = 0, # Bottom margin
l = 1, # Left margin
unit = "cm"))
```
### Final plot
Last few tweaks made on Canva
{fig-align="center" width="597"}