require(pacman)
p_load(tidytuesdayR, trashpanda, magick, tidyverse, janitor, tidytext, extrafont, slider, here, TTR, sf, rnaturalearth, rnaturalearthdata, patchwork, hexbin)Australian Frogs
Load Packages
Load Data
tuesdata <- tidytuesdayR::tt_load('2025-09-02')
frogs <- tuesdata$frogID_data
frog_names <- tuesdata$frog_namesClean Data
frogs <- frogs |>
clean_names()
frogs_unique <- frogs %>%
distinct(decimal_longitude, decimal_latitude, scientific_name)
aus_states <- ne_states(country = "australia", returnclass = "sf") |>
filter(name != "Macquarie Island")Plot
plot <- ggplot(frogs_unique, aes(x = decimal_longitude, y = decimal_latitude)) +
stat_summary_hex(
aes(z = as.numeric(factor(scientific_name))),
fun = function(x) length(unique(x)),
bins = 50
) +
geom_sf(data = aus_states, fill = NA, colour = "black", size = 0.5, inherit.aes = FALSE) +
coord_sf() +
scale_fill_viridis_c(option = "plasma") +
labs(
title = "Australian Frog Species Richness",
subtitle = "Number of unique frog species recorded per hexagon across Australia in 2023",
fill = "Species Richness") +
theme_void() +
add_caption_cwb(type = "plot", include_data_source = TRUE, data_source = "Australian Society of Herpetologists") +
theme(
plot.background = element_rect(fill = "grey99", color = NA),
plot.title = element_text(face = "bold", size = 25, hjust = 0.5),
plot.subtitle = element_text(size = 15, hjust = 0.5),
legend.position = "top",
legend.key.width = unit(3, "lines"),
legend.title = element_text(face = "bold", size = 15, hjust = 0.5),
legend.title.position = "top",
legend.text = element_text(size = 12),
plot.margin = margin(10, 10, 10, 10)
)
# Save and display images
current_dir <- dirname(knitr::current_input())
plot_name <- "australian_frogs.png"
ggsave(plot = plot,
dpi = "screen",
width = 18,
height = 18,
device = ragg::agg_png,
filename = file.path(current_dir, plot_name))
# Read the big plot
img <- image_read(file.path(current_dir, plot_name))
# Force 16:9 aspect ratio with minimal padding
# Target size: 1200x675 px (16:9)
img_card <- image_scale(img, "1200x675") # scale to fit inside 16:9
img_card <- image_extent(
img_card,
geometry = "1200x675",
gravity = "center"
)
# Save as card preview
image_write(img_card, path = file.path(current_dir, "preview.png"))
knitr::include_graphics(
file.path(current_dir, plot_name)
)
References
trashpanda::cite_packages(format = "rmd")Carr D, Lewin-Koh N, Maechler M, Sarkar D (2024). hexbin: Hexagonal Binning Routines. doi:10.32614/CRAN.package.hexbin https://doi.org/10.32614/CRAN.package.hexbin, R package version 1.28.5, https://CRAN.R-project.org/package=hexbin.
Pedersen T (2025). patchwork: The Composer of Plots. doi:10.32614/CRAN.package.patchwork https://doi.org/10.32614/CRAN.package.patchwork, R package version 1.3.2, https://CRAN.R-project.org/package=patchwork.
South A, Michael S, Massicotte P (2024). rnaturalearthdata: World Vector Map Data from Natural Earth Used in ‘rnaturalearth’. doi:10.32614/CRAN.package.rnaturalearthdata https://doi.org/10.32614/CRAN.package.rnaturalearthdata, R package version 1.0.0, https://CRAN.R-project.org/package=rnaturalearthdata.
Massicotte P, South A (2026). rnaturalearth: World Map Data from Natural Earth. doi:10.32614/CRAN.package.rnaturalearth https://doi.org/10.32614/CRAN.package.rnaturalearth, R package version 1.2.0, https://CRAN.R-project.org/package=rnaturalearth.
Pebesma E, Bivand R (2023). Spatial Data Science: With applications in R. Chapman and Hall/CRC. doi:10.1201/9780429459016 https://doi.org/10.1201/9780429459016, https://r-spatial.org/book/.
Pebesma E (2018). “Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal, 10(1), 439-446. doi:10.32614/RJ-2018-009 https://doi.org/10.32614/RJ-2018-009, https://doi.org/10.32614/RJ-2018-009.
Ulrich J (2023). TTR: Technical Trading Rules. doi:10.32614/CRAN.package.TTR https://doi.org/10.32614/CRAN.package.TTR, R package version 0.24.4, https://CRAN.R-project.org/package=TTR.
Müller K (2025). here: A Simpler Way to Find Your Files. doi:10.32614/CRAN.package.here https://doi.org/10.32614/CRAN.package.here, R package version 1.0.2, https://CRAN.R-project.org/package=here.
Vaughan D (2025). slider: Sliding Window Functions. doi:10.32614/CRAN.package.slider https://doi.org/10.32614/CRAN.package.slider, R package version 0.3.3, https://CRAN.R-project.org/package=slider.
Chang W (2025). extrafont: Tools for Using Fonts. doi:10.32614/CRAN.package.extrafont https://doi.org/10.32614/CRAN.package.extrafont, R package version 0.20, https://CRAN.R-project.org/package=extrafont.
Silge J, Robinson D (2016). “tidytext: Text Mining and Analysis Using Tidy Data Principles in R.” JOSS, 1(3). doi:10.21105/joss.00037 https://doi.org/10.21105/joss.00037, http://dx.doi.org/10.21105/joss.00037.
Firke S (2024). janitor: Simple Tools for Examining and Cleaning Dirty Data. doi:10.32614/CRAN.package.janitor https://doi.org/10.32614/CRAN.package.janitor, R package version 2.2.1, https://CRAN.R-project.org/package=janitor.
Grolemund G, Wickham H (2011). “Dates and Times Made Easy with lubridate.” Journal of Statistical Software, 40(3), 1-25. https://www.jstatsoft.org/v40/i03/.
Wickham H (2025). forcats: Tools for Working with Categorical Variables (Factors). doi:10.32614/CRAN.package.forcats https://doi.org/10.32614/CRAN.package.forcats, R package version 1.0.1, https://CRAN.R-project.org/package=forcats.
Wickham H (2025). stringr: Simple, Consistent Wrappers for Common String Operations. doi:10.32614/CRAN.package.stringr https://doi.org/10.32614/CRAN.package.stringr, R package version 1.6.0, https://CRAN.R-project.org/package=stringr.
Wickham H, François R, Henry L, Müller K, Vaughan D (2023). dplyr: A Grammar of Data Manipulation. doi:10.32614/CRAN.package.dplyr https://doi.org/10.32614/CRAN.package.dplyr, R package version 1.1.4, https://CRAN.R-project.org/package=dplyr.
Wickham H, Henry L (2026). purrr: Functional Programming Tools. doi:10.32614/CRAN.package.purrr https://doi.org/10.32614/CRAN.package.purrr, R package version 1.2.1, https://CRAN.R-project.org/package=purrr.
Wickham H, Hester J, Bryan J (2025). readr: Read Rectangular Text Data. doi:10.32614/CRAN.package.readr https://doi.org/10.32614/CRAN.package.readr, R package version 2.1.6, https://CRAN.R-project.org/package=readr.
Wickham H, Vaughan D, Girlich M (2025). tidyr: Tidy Messy Data. doi:10.32614/CRAN.package.tidyr https://doi.org/10.32614/CRAN.package.tidyr, R package version 1.3.2, https://CRAN.R-project.org/package=tidyr.
Müller K, Wickham H (2026). tibble: Simple Data Frames. doi:10.32614/CRAN.package.tibble https://doi.org/10.32614/CRAN.package.tibble, R package version 3.3.1, https://CRAN.R-project.org/package=tibble.
Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. ISBN 978-3-319-24277-4, https://ggplot2.tidyverse.org.
Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R, Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V, Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). “Welcome to the tidyverse.” Journal of Open Source Software, 4(43), 1686. doi:10.21105/joss.01686 https://doi.org/10.21105/joss.01686.
Ooms J (2025). magick: Advanced Graphics and Image-Processing in R. doi:10.32614/CRAN.package.magick https://doi.org/10.32614/CRAN.package.magick, R package version 2.9.0, https://CRAN.R-project.org/package=magick.
Baril C (????). trashpanda: Cole’s Personal Collection of R Functions, Themes, and Palettes. R package version 0.0.1, https://colebaril.github.io/trashpanda/.
Harmon J, Hughes E (2025). tidytuesdayR: Access the Weekly ‘TidyTuesday’ Project Dataset. doi:10.32614/CRAN.package.tidytuesdayR https://doi.org/10.32614/CRAN.package.tidytuesdayR, R package version 1.2.1, https://CRAN.R-project.org/package=tidytuesdayR.
Rinker TW, Kurkiewicz D (2018). pacman: Package Management for R. version 0.5.0, http://github.com/trinker/pacman.