I am curious about the geographical participation in the #30DayMapChallenge, so I thought it may be a good opportunity to learn the R-package rtweet and see if I can map from where people are twitting.
In the present post we will learn how to animate ggplot objects with gganimate. For that, we will create an animated map that represents the total population change in Denmark from 2008 to 2021.
In this tutorial we will see how to plot spatial data in R. We will use ggplot2 because we can apply what we already have learnt about creating graphs.
In the previous post we saw how to plot line charts in R using the package ggplot2. I will continue with this topic and we will learn additional features that may be useful for data visualization, in particular:
My previous post was about how we can download data from Statistic Denmark. Here, we will use these data for learning to plot line charts in R using ggplot2.
Get data to play with is a key part for learning R and therefore any source of public data is more than welcome. In this regard, I recently come across the danstat package.
Plot the temperature of the air at about 2m above the surface (i.e. monthly averages).
Packages we are going to use:
library(raster) library(animation) library(ncdf4) library(sf) library(ggplot2) library(rworldmap) library(rworldxtra) Firstly, I have downloaded the monthly average temperatures from ECMWF.
I tested cartography.
Load packages:
library(sf) library(cartography) # path to the geopackage file embedded in cartography path_to_gpkg <- system.file("gpkg/mtq.gpkg", package="cartography") # import to an sf object mtq <- st_read(dsn = path_to_gpkg, quiet = TRUE) # Compute the population density (inhab.
I plotted an interactive map with R.
Load packages we are going to use:
library(sf) library(tidyverse) library(leaflet) Download roads (OSi - National 250k Map of Ireland) from the Ordnance Survey Ireland dir.
I plotted the European river catchments changing the default settings in ggplot2 to different scales of blue (e.g. background, grids, etc.).
Load packages:
library(sf) library(tidyverse) library(rworldmap) library(rworldxtra) Download the European river catchments from the European Environment Agency: dir.