diff --git a/.github/workflows/update-docs.yaml b/.github/workflows/update-docs.yaml index 88a13516..584b3cf3 100644 --- a/.github/workflows/update-docs.yaml +++ b/.github/workflows/update-docs.yaml @@ -30,7 +30,7 @@ jobs: - name: Update docs run: | - pkgdev::update_docs(opt_dir = c("man/figures", "img", "vignettes"),) + pkgdev::update_docs(opt_dir = c("man/figures", "img", "vignettes")) shell: Rscript {0} diff --git a/README.Rmd b/README.Rmd index 83f3df60..6f52972e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -223,18 +223,22 @@ nuts3_sf <- nuts3 %>% # Breaks and labels br <- c(0, 25, 50, 100, 200, 500, 1000, 2500, 5000, 10000, 30000) +labs <- prettyNum(br[-1], big.mark = ",") +# Label function to be used in the plot, mainly for NAs +labeller_plot <- function(x) { + ifelse(is.na(x), "No Data", x) +} nuts3_sf <- nuts3_sf %>% - mutate(values_cut = cut(values, br, dig.lab = 5)) + # Cut with labels + mutate(values_cut = cut(values, br, labels = labs)) -labs_plot <- prettyNum(br[-1], big.mark = ",") # Palette -pal <- hcl.colors(length(br) - 1, "Lajolla") +pal <- hcl.colors(length(labs), "Lajolla") # Plot - ggplot(nuts3_sf) + geom_sf(aes(fill = values_cut), linewidth = 0, color = NA, alpha = 0.9) + geom_sf(data = country_lines, col = "black", linewidth = 0.1) + @@ -245,7 +249,9 @@ ggplot(nuts3_sf) + ) + # Legends scale_fill_manual( - values = pal, labels = labs_plot, + values = pal, + # Label for NA + labels = labeller_plot, drop = FALSE, guide = guide_legend(direction = "horizontal", nrow = 1) ) + # Theming @@ -276,7 +282,8 @@ ggplot(nuts3_sf) + fill = "people per sq. kilometer", caption = paste0( "Source: Eurostat, ", gisco_attributions(), - "\nBased on Milos Popovic: https://milospopovic.net/how-to-make-choropleth-map-in-r/" + "\nBased on Milos Popovic: ", + "https://milospopovic.net/how-to-make-choropleth-map-in-r/" ) ) ``` diff --git a/README.md b/README.md index 727011eb..666138dc 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ We now download the data from Eurostat: library(eurostat) popdens <- get_eurostat("demo_r_d3dens") %>% filter(TIME_PERIOD == "2021-01-01") +#> indexed 0B in 0s, 0B/sindexed 1.00TB in 0s, 426.08TB/s ``` By last, we merge and manipulate the data for creating the final plot: @@ -199,18 +200,22 @@ nuts3_sf <- nuts3 %>% # Breaks and labels br <- c(0, 25, 50, 100, 200, 500, 1000, 2500, 5000, 10000, 30000) +labs <- prettyNum(br[-1], big.mark = ",") +# Label function to be used in the plot, mainly for NAs +labeller_plot <- function(x) { + ifelse(is.na(x), "No Data", x) +} nuts3_sf <- nuts3_sf %>% - mutate(values_cut = cut(values, br, dig.lab = 5)) + # Cut with labels + mutate(values_cut = cut(values, br, labels = labs)) -labs_plot <- prettyNum(br[-1], big.mark = ",") # Palette -pal <- hcl.colors(length(br) - 1, "Lajolla") +pal <- hcl.colors(length(labs), "Lajolla") # Plot - ggplot(nuts3_sf) + geom_sf(aes(fill = values_cut), linewidth = 0, color = NA, alpha = 0.9) + geom_sf(data = country_lines, col = "black", linewidth = 0.1) + @@ -221,7 +226,9 @@ ggplot(nuts3_sf) + ) + # Legends scale_fill_manual( - values = pal, labels = labs_plot, + values = pal, + # Label for NA + labels = labeller_plot, drop = FALSE, guide = guide_legend(direction = "horizontal", nrow = 1) ) + # Theming @@ -252,7 +259,8 @@ ggplot(nuts3_sf) + fill = "people per sq. kilometer", caption = paste0( "Source: Eurostat, ", gisco_attributions(), - "\nBased on Milos Popovic: https://milospopovic.net/how-to-make-choropleth-map-in-r/" + "\nBased on Milos Popovic: ", + "https://milospopovic.net/how-to-make-choropleth-map-in-r/" ) ) ``` @@ -353,8 +361,7 @@ This package is in no way officially related to or endorsed by Eurostat. ## References -
+
diff --git a/img/README-example-1.png b/img/README-example-1.png index 9dac181f..28ef684c 100644 Binary files a/img/README-example-1.png and b/img/README-example-1.png differ diff --git a/img/README-example-2.png b/img/README-example-2.png index 4b6cbf62..2a4bc624 100644 Binary files a/img/README-example-2.png and b/img/README-example-2.png differ diff --git a/img/README-labels-1.png b/img/README-labels-1.png index 2c53689a..1c666981 100644 Binary files a/img/README-labels-1.png and b/img/README-labels-1.png differ diff --git a/img/README-thematic-1.png b/img/README-thematic-1.png index 3fe17fe0..f2ab5f7c 100644 Binary files a/img/README-thematic-1.png and b/img/README-thematic-1.png differ