diff --git a/pkgdown/extra.css b/pkgdown/extra.css index 61fd9ba..fda5f53 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -55,6 +55,11 @@ a.anchor { color: var(--nav-bkg) !important; } +/* button padding */ +li.nav-item { + padding-right: .5em; +} + /* package name in navbar */ .navbar-brand { color: var(--nav-link) !important; @@ -224,3 +229,9 @@ h4 { background-color: var(--toc-hover); color: var(--toc-htext) !important; } + +/* Vignette tables ---------------------------------------------------------- */ +table.taylor-examples td { + width: 33.333%; + vertical-align: middle; +} diff --git a/vignettes/children/chunk-options.txt b/vignettes/children/chunk-options.txt index a7ec835..b38d654 100644 --- a/vignettes/children/chunk-options.txt +++ b/vignettes/children/chunk-options.txt @@ -12,6 +12,7 @@ knitr::opts_chunk$set( comment = "#>", fig.asp = 0.618, fig.width = small_width, + fig.align = "center", out.width = "90%" ) diff --git a/vignettes/data/example-uses.csv b/vignettes/data/example-uses.csv new file mode 100644 index 0000000..4254d94 --- /dev/null +++ b/vignettes/data/example-uses.csv @@ -0,0 +1,10 @@ +preview,href,description +https://juliasilge.com/blog/taylor-swift/index_files/figure-html/unnamed-chunk-10-1.png,https://juliasilge.com/blog/taylor-swift/,Julia Silge topic modeling +https://cdn.fosstodon.org/media_attachments/files/111/275/600/691/928/622/original/d3cadbb47844dc21.png,https://fosstodon.org/@ryanahart/111275600981010402,Crafting bracelets +https://cdn.masto.host/vissocial/media_attachments/files/111/268/872/636/513/756/original/438db8d1a9fc47ef.png,https://vis.social/@georgios/111268873077992577,Danceability beeswarm +https://cdn.fosstodon.org/media_attachments/files/111/263/533/563/532/762/original/2286c64153a24511.png,https://fosstodon.org/@nrennie/111263534136045526,Average energy +https://cdn.fosstodon.org/media_attachments/files/111/256/276/115/381/437/original/452faf0a9aca766e.png,https://fosstodon.org/@ryanahart/111256276399597870,Swiftly shifting tempos +https://cdn.fosstodon.org/media_attachments/files/111/250/751/304/784/167/original/89c6862657cac335.png,https://fosstodon.org/@deepali/111250751714226638,Song duration radial +https://fediscience.org/system/media_attachments/files/111/249/262/791/175/938/original/ecaebe4b66d85c8b.jpg,https://fediscience.org/@c_borstell/111246953936265713,Albums as sheet music +https://cdn.fosstodon.org/media_attachments/files/111/270/764/662/176/750/original/4986ef0af073cd51.png,https://fosstodon.org/@danoehm/111270774940496937,Eras tour breakdown +https://cdn.fosstodon.org/media_attachments/files/111/250/191/920/048/768/original/f5dcdfc73d0c6af7.png,https://fosstodon.org/@frankhaenel/111250193319291887,Spotify metrics radial \ No newline at end of file diff --git a/vignettes/taylor.Rmd b/vignettes/taylor.Rmd new file mode 100644 index 0000000..4cbf2be --- /dev/null +++ b/vignettes/taylor.Rmd @@ -0,0 +1,136 @@ +--- +title: "Welcome to taylor" +description: | + Learn about the package and what it can do! +vignette: > + %\VignetteIndexEntry{Introduction to taylor} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, child="children/chunk-options.txt"} +``` + +taylor is an R package for accessing data + +```{r setup} +library(taylor) +``` + +
Plot code + +```{r eras-plot, eval = FALSE} +library(dplyr) +library(tidyr) +library(ggplot2) + +surprise_song_count <- eras_tour_surprise %>% + nest(dat = -c(leg, date, city, night)) %>% + arrange(date) %>% + mutate(leg = factor(leg, levels = unique(eras_tour_surprise$leg), + labels = c("North America\n(Leg 1)", + "South\nAmerica", + "Asia-Pacific"))) %>% + mutate(show_number = 1:n(), .after = night) %>% + unnest(dat) %>% + left_join(distinct(taylor_album_songs, track_name, album_name), + join_by(song == track_name), + relationship = "many-to-one") %>% + count(leg, date, city, night, show_number, album_name) %>% + complete(nesting(leg, date, city, night, show_number), album_name) %>% + mutate(n = replace_na(n, 0)) %>% + arrange(album_name, date, night) %>% + mutate(surprise_count = cumsum(n), .by = album_name) %>% + mutate(album_name = replace_na(album_name, "Other"), + album_name = factor(album_name, c(album_levels, "Other")), + album_group = album_name) + +ggplot(surprise_song_count) + + facet_wrap(~ album_name, ncol = 3) + + geom_line(data = ~select(.x, -album_name), + aes(x = show_number, y = surprise_count, group = album_group), + color = "grey80", na.rm = TRUE) + + geom_line(aes(x = show_number, y = surprise_count, color = album_name), + show.legend = FALSE, linewidth = 2, na.rm = TRUE) + + scale_color_albums(na.value = "grey80") + + labs(x = "Show", y = "Songs Played") + + theme_minimal() + + theme(strip.text.x = element_text(hjust = 0, size = 10), + axis.title = element_text(size = 9)) +``` + +
+ +```{r eras-plot, echo = FALSE, message = FALSE, warning = FALSE} +#| fig-asp: 1.1 +#| fig-alt: > +#| A series of line plots showing the increases in the total number of songs +#| from each album that Taylor has played as surprise songs during The Eras +#| Tour. +``` + +Some test. + +```{r, eval = FALSE} +missing_firsts <- tibble(date = as.Date(c("2023-11-01", + "2024-02-01"))) +day_ones <- surprise_song_count %>% + slice_min(date, by = c(leg, album_name)) %>% + select(leg, date, album_name) %>% + mutate(date = date - lubridate::ddays(1)) + +surprise_song_count %>% + bind_rows(missing_firsts) %>% + arrange(date) %>% + fill(leg, .direction = "up") %>% + bind_rows(day_ones) %>% + arrange(album_name, date) %>% + group_by(album_name) %>% + fill(surprise_count, .direction = "down") %>% + ggplot() + + facet_grid(cols = vars(leg), scales = "free_x", space = "free_x") + + geom_line(aes(x = date, y = surprise_count, group = album_name), + color = "grey80", na.rm = TRUE) + + geom_line(data = ~filter(.x, album_name == "1989 (Taylor's Version)"), + aes(x = date, y = surprise_count, color = album_name), + show.legend = FALSE, size = 2, na.rm = TRUE) + + scale_color_albums() + + scale_x_date(breaks = "month", date_labels = "%b %Y", expand = c(.02, .02)) + + theme_minimal() + + theme(strip.text.x = element_text(hjust = 0)) +``` + + +## I could show you incredible things + +There are many ways we can explore the data, but, honestly, baby, who's counting? +Below is a collection of analyses that use data from taylor that I have found in the wild. +If you use the data and find it useful, please reach out---I love to see the package used! + +```{r examples, echo = FALSE, results = "asis"} +examples <- read.csv("data/example-uses.csv") +cells <- paste("", + paste0(" "), + paste0(" "), + " ", + "", + sep = "\n") + +needed_rows <- ceiling(length(cells) / 3) +rows <- vapply(seq_len(needed_rows), + function(x) { + paste("", + paste(cells[((x * 3) - 2):(x * 3)], collapse = "\n"), + "", + sep = "\n") + }, + character(1)) + +tab <- paste("", + paste(rows, collapse = "\n"), + "
", + sep = "\n") + +cat(tab) +```