Create an interactive plot for the number of alien species per native region and year of introduction
Source:R/indicator_native_range_year.R
indicator_native_range_year.Rd
Based on countYearProvince plot from reporting - rshiny - grofwildjacht
Usage
indicator_native_range_year(
df,
years = NULL,
type = c("native_range", "native_continent"),
x_lab = "year",
y_lab = "alien species",
relative = FALSE,
first_observed = "first_observed"
)
Arguments
- df
input data.frame.
- years
(numeric) vector years we are interested to. If
NULL
(default) all years from minimum and maximum of years of first observation are taken into account.- type
character, native_range level of interest should be one of
c("native_range", "native_continent")
. Default:"native_range"
. A column called as the selectedtype
must be present indf
.- x_lab
character string, label of the x-axis. Default: "year".
- y_lab
character string, label of the y-axis. Default: "number of alien species".
- relative
(logical) if TRUE (default), each bar is standardised before stacking.
- first_observed
(character) Name of the column in
data
containing temporal information about introduction of the alien species. Expressed as years.
Value
list with:
'static_plot': ggplot object, for a given species the observed number per year and per native range is plotted in a stacked bar chart
'interactive_plot': plotly object, for a given species the observed number per year and per native range is plotted in a stacked bar chart
'data': data displayed in the plot, as data.frame with:
'year': year at which the species were introduced
'native_range': native range of the introduced species
'n': number of species introduced from the native range for a given year
'total': total number of species, from all around the world, introduced during a given year
'perc': percentage of species introduced from the native range for a given year. (n/total)*100
Examples
if (FALSE) {
library(readr)
datafile <- paste0(
"https://raw.githubusercontent.com/trias-project/indicators/master/data/",
"interim/data_input_checklist_indicators.tsv"
)
data <- read_tsv(datafile,
na = "",
col_types = cols(
.default = col_character(),
key = col_double(),
nubKey = col_double(),
speciesKey = col_double(),
first_observed = col_double(),
last_observed = col_double()
)
)
indicator_native_range_year(data, "native_continent", years = c(2010,2013))
}