Skip to content

Commit

Permalink
start getting started vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakethompson committed Apr 18, 2024
1 parent 670a8eb commit c3905b6
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkgdown/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions vignettes/children/chunk-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ knitr::opts_chunk$set(
comment = "#>",
fig.asp = 0.618,
fig.width = small_width,
fig.align = "center",
out.width = "90%"
)

Expand Down
10 changes: 10 additions & 0 deletions vignettes/data/example-uses.csv
Original file line number Diff line number Diff line change
@@ -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
136 changes: 136 additions & 0 deletions vignettes/taylor.Rmd
Original file line number Diff line number Diff line change
@@ -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)
```

<details><summary>Plot code</summary>

```{r eras-plot, eval = FALSE}
library(dplyr)
library(tidyr)
library(ggplot2)
surprise_song_count <- eras_tour_surprise %>%

Check warning on line 27 in vignettes/taylor.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/taylor.Rmd,line=27,col=46,[trailing_whitespace_linter] Trailing whitespace is superfluous.
nest(dat = -c(leg, date, city, night)) %>%

Check warning on line 28 in vignettes/taylor.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/taylor.Rmd,line=28,col=45,[trailing_whitespace_linter] Trailing whitespace is superfluous.
arrange(date) %>%

Check warning on line 29 in vignettes/taylor.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/taylor.Rmd,line=29,col=20,[trailing_whitespace_linter] Trailing whitespace is superfluous.
mutate(leg = factor(leg, levels = unique(eras_tour_surprise$leg),
labels = c("North America\n(Leg 1)",
"South\nAmerica",
"Asia-Pacific"))) %>%

Check warning on line 33 in vignettes/taylor.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/taylor.Rmd,line=33,col=55,[trailing_whitespace_linter] Trailing whitespace is superfluous.
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))
```

</details>

```{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("<td>",
paste0(" <a href=\"", examples$href, "\">"),
paste0(" <img src=\"", examples$preview, "\" ",
"alt=\"", examples$description, "\" width=\"100%\"/>"),
" </a>",
"</td>",
sep = "\n")
needed_rows <- ceiling(length(cells) / 3)
rows <- vapply(seq_len(needed_rows),
function(x) {
paste("<tr>",
paste(cells[((x * 3) - 2):(x * 3)], collapse = "\n"),
"</tr>",
sep = "\n")
},
character(1))
tab <- paste("<table class=\"taylor-examples\" width=\"100%\">",
paste(rows, collapse = "\n"),
"</table>",
sep = "\n")
cat(tab)
```

0 comments on commit c3905b6

Please sign in to comment.