View source: R/plot_countries.R
plot_countries | R Documentation |
Plots country values on a map using data provided and allows customisation of various aesthetics, such as colors, legend title, and title.
plot_countries(
data,
iso_col,
values_col,
colors = NULL,
na_value = "grey",
title = NULL,
legend_title = NULL
)
data |
A data frame containing the values to be plotted on the map. |
iso_col |
A string specifying the column name in |
values_col |
A string specifying the column name in |
colors |
Optional vector of colors used in the gradient scale. |
na_value |
Color for missing values (default is "grey"). |
title |
A title for the plot (default is |
legend_title |
A title for the legend. Default |
Extracts an sf
object from the giscoR
package.
It uses the ggplot2
package for the representation. Also, it supports the addition
of other ggplot2
options (see examples).
A ggplot
object with the plotted countries.
# Simulated data trade in Northern America
data("datatrade_NorthAm")
# Mean of internal production for each country
library(dplyr)
data_plot <- datatrade_NorthAm$internal_production %>%
group_by(reporter) %>%
summarise(mean_value = mean(value))
head(data_plot)
#Plot
pl <- plot_countries(data = data_plot,
iso_col = "reporter",
values_col = "mean_value")
pl
# Changing colors and adding other ggplot2 options
library(ggplot2)
pl <- plot_countries(data = data_plot,
iso_col = "reporter",
values_col = "mean_value",
colors = c("white", "lightblue", "darkblue"),
title = "Plot internal production",
legend_title = "units")
pl +
xlim(-170, -20) + ylim(10, 90) +
theme_bw()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.