--- title: "Tourism data" format: html: toc: true toc-depth: 2 number-sections: true toc-location: left fig-cap-location: top code-fold: false code-tools: true theme: flatly page-layout: full editor: visual vignette: > %\VignetteIndexEntry{tourism data} %\VignetteEngine{quarto::html} %\VignetteEncoding{UTF-8} --- ```{r, echo=FALSE, message=FALSE, warning=FALSE} # Ensure the temporary library from R CMD check is visible (esp. on Windows) libdir <- Sys.getenv("R_LIBS") if (nzchar(libdir)) { parts <- strsplit(libdir, .Platform$path.sep, fixed = TRUE)[[1]] .libPaths(unique(c(parts, .libPaths()))) } # now load your package suppressPackageStartupMessages(library(ecotourism)) ``` **What this vignette covers**\ This vignette provides a quick tour of the `ecotourism` package’s tourism datasets. You’ll learn how to join quarterly counts with regional metadata, and optionally how to enrich the data by linking each region to its nearest weather station. - Because of its size, the tourism dataset was split into two separate datasets, with a shared key provided for joining them. ## Data overview This is the glimpse of your data : ```{r, echo=TRUE, eval=TRUE, message=FALSE, warning=FALSE} library(dplyr) library(ecotourism) data("tourism_region") tourism_region |> glimpse() ``` ```{r, echo=TRUE, eval=TRUE, message=FALSE, warning=FALSE} data("tourism_quarterly") tourism_quarterly |> glimpse() ``` ------------------------------------------------------------------------ ## Join regional metadata to quarterly counts We keep only rows with a valid region name after the join. ```{r, echo=FALSE, eval=TRUE, message=FALSE, warning=FALSE} tourism <- tourism_quarterly |> left_join(tourism_region, by = c("region_id", "ws_id")) |> filter(!is.na(region)) glimpse(tourism) ``` If you only need a subset of columns, select them first to keep memory small, for example: `select(region_id, quarter, visitors, lon, lat)`. ## Optional: add nearest weather station metadata If your quarterly table contains a `ws_id`, you can join station attributes: ```{r, echo=FALSE, eval=TRUE, message=FALSE, warning=FALSE} tourism <- tourism |> dplyr::left_join(ecotourism::weather_stations, by = "ws_id") ``` ## A quick map We’ll plot tourism site coordinates and, when available, their weather stations. ```{r echo=TRUE, fig.width=6, fig.height=4, eval=FALSE} library(ggplot2) library(ggthemes) ggplot() + geom_sf(data = oz_lga) + geom_point(data = tourism, aes(x = lon, y = lat), alpha = 0.8, size = 0.5) + theme_map() ``` If station coordinates `stn_lon` and `stn_lat` are present, overlay them too: ```{r echo=TRUE, fig.width=6, fig.height=4, eval=TRUE} library(ggplot2) library(ggthemes) ggplot() + geom_sf(data = oz_lga) + geom_point(data = tourism, aes(x = lon, y = lat), alpha = 0.5, size = 0.4, color = "blue") + geom_point(data = tourism, aes(x = stn_lon, y = stn_lat), shape = 17, size = 0.5, alpha = 0.5, color = "red") + theme_map() ```