--- title: "Epiverse-TRACE ggplot2 theme and scale demo" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Epiverse-TRACE ggplot2 theme and scale demo} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.height = tracetheme::vignette_dim$vig_height, fig.width = tracetheme::vignette_dim$vig_width, fig.showtext = TRUE ) showtext::showtext_opts(dpi = 120) ``` ```{r setup} library(tracetheme) library(ggplot2) theme_set(theme_trace()) ``` The examples below are taken from [ggplot2 documentation](https://ggplot2.tidyverse.org/) and are intended to demonstrate the effect of the `theme_trace()` and `scale_trace()` functions. ## Line graphs/time series ```{r} ggplot(economics, aes(date, unemploy)) + geom_line() + labs( title = "Unemployment over time", subtitle = "From July 1967 to April 2015", caption = "Data source: https://fred.stlouisfed.org/", x = "Date", y = "Unemployment" ) ``` ## Scatter plots ```{r} ggplot(mtcars, aes(wt, mpg)) + geom_point() ``` ## Bar / column charts ```{r} ggplot(mpg, aes(class)) + geom_bar() ``` ## Maps ```{r} crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests) # Equivalent to crimes %>% tidyr::pivot_longer(Murder:Rape) vars <- lapply(names(crimes)[-1], function(j) { data.frame(state = crimes$state, variable = j, value = crimes[[j]]) }) crimes_long <- do.call("rbind", vars) states_map <- map_data("state") ggplot(crimes_long, aes(map_id = state)) + geom_map(aes(fill = value), map = states_map) + coord_sf( crs = 5070, default_crs = 4326, xlim = c(-125, -70), ylim = c(25, 52) ) + facet_wrap(~variable) + labs( # multi-line title title = "Number of arrests in the United States\ndisaggregated by reason" ) ``` ## Distribution plots (parametric and non-parametric) ```{r} ggplot() + geom_function(fun = dnorm) + xlim(-5, 5) ``` ## Densities ```{r} ggplot(diamonds, aes(carat)) + geom_density() ``` ## Heatmaps ```{r} ggplot(faithful, aes(x = eruptions, y = waiting)) + geom_point() + geom_density_2d_filled(alpha = 0.5) ``` ```{r} ggplot(diamonds, aes(x, y)) + geom_bin_2d() ``` ## Networks This example is pulled from ggraph documentation ```{r} library(ggraph) library(tidygraph) set_graph_style(plot_margin = margin(1, 1, 1, 1)) graph <- as_tbl_graph(highschool) # Not specifying the layout - defaults to "auto" ggraph(graph) + geom_edge_link(aes(colour = factor(year))) + geom_node_point() ``` ## Concept maps / flowcharts