|
| 1 | +### Please add alt text to your posts |
| 2 | + |
| 3 | +Please add alt text (alternative text) to all of your posted graphics for `#TidyTuesday`. |
| 4 | + |
| 5 | +Twitter provides [guidelines](https://help.twitter.com/en/using-twitter/picture-descriptions) for how to add alt text to your images. |
| 6 | + |
| 7 | +The DataViz Society/Nightingale by way of Amy Cesal has an [article](https://medium.com/nightingale/writing-alt-text-for-data-visualization-2a218ef43f81) on writing _good_ alt text for plots/graphs. |
| 8 | + |
| 9 | +> Here’s a simple formula for writing alt text for data visualization: |
| 10 | +> ### Chart type |
| 11 | +> It’s helpful for people with partial sight to know what chart type it is and gives context for understanding the rest of the visual. |
| 12 | +> Example: Line graph |
| 13 | +> ### Type of data |
| 14 | +> What data is included in the chart? The x and y axis labels may help you figure this out. |
| 15 | +> Example: number of bananas sold per day in the last year |
| 16 | +> ### Reason for including the chart |
| 17 | +> Think about why you’re including this visual. What does it show that’s meaningful. There should be a point to every visual and you should tell people what to look for. |
| 18 | +> Example: the winter months have more banana sales |
| 19 | +> ### Link to data or source |
| 20 | +> Don’t include this in your alt text, but it should be included somewhere in the surrounding text. People should be able to click on a link to view the source data or dig further into the visual. This provides transparency about your source and lets people explore the data. |
| 21 | +> Example: Data from the USDA |
| 22 | +
|
| 23 | +Penn State has an [article](https://accessibility.psu.edu/images/charts/) on writing alt text descriptions for charts and tables. |
| 24 | + |
| 25 | +> Charts, graphs and maps use visuals to convey complex images to users. But since they are images, these media provide serious accessibility issues to colorblind users and users of screen readers. See the [examples on this page](https://accessibility.psu.edu/images/charts/) for details on how to make charts more accessible. |
| 26 | +
|
| 27 | +The `{rtweet}` package includes the [ability to post tweets](https://docs.ropensci.org/rtweet/reference/post_tweet.html) with alt text programatically. |
| 28 | + |
| 29 | +Need a **reminder**? There are [extensions](https://chrome.google.com/webstore/detail/twitter-required-alt-text/fpjlpckbikddocimpfcgaldjghimjiik/related) that force you to remember to add Alt Text to Tweets with media. |
| 30 | + |
| 31 | +# Hollywood Age Gaps |
| 32 | + |
| 33 | +The data this week comes from [Hollywood Age Gap](https://hollywoodagegap.com/) via [Data Is Plural](https://www.data-is-plural.com/archive/2018-02-07-edition/). |
| 34 | + |
| 35 | +> An informational site showing the age gap between movie love interests. |
| 36 | +
|
| 37 | +The data follows certain rules: |
| 38 | + |
| 39 | +> The two (or more) actors play actual love interests (not just friends, coworkers, or some other non-romantic type of relationship) |
| 40 | +
|
| 41 | +> The youngest of the two actors is at least 17 years old |
| 42 | +
|
| 43 | +> Not animated characters |
| 44 | +
|
| 45 | +We previously provided a dataset about the [Bechdel Test](https://tidytues.day/2021/2021-03-09). It might be interesting to see whether there is any correlation between these datasets! The Bechdel Test dataset also included additional information about the films that were used in that dataset. |
| 46 | + |
| 47 | +Note: The age gaps dataset includes "gender" columns, which always contain the values "man" or "woman". These values appear to indicate how the *characters* in each film identify. Some of these values do not match how the *actor* identifies. We apologize if any characters are misgendered in the data! |
| 48 | + |
| 49 | +### Get the data here |
| 50 | + |
| 51 | +```{r} |
| 52 | +# Get the Data |
| 53 | +
|
| 54 | +# Read in with tidytuesdayR package |
| 55 | +# Install from CRAN via: install.packages("tidytuesdayR") |
| 56 | +# This loads the readme and all the datasets for the week of interest |
| 57 | +
|
| 58 | +# Either ISO-8601 date or year/week works! |
| 59 | +
|
| 60 | +tuesdata <- tidytuesdayR::tt_load('2023-02-14') |
| 61 | +tuesdata <- tidytuesdayR::tt_load(2023, week = 7) |
| 62 | +
|
| 63 | +age_gaps <- tuesdata$age_gaps |
| 64 | +
|
| 65 | +# Or read in the data manually |
| 66 | +
|
| 67 | +age_gaps <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-02-14/age_gaps.csv') |
| 68 | +``` |
| 69 | + |
| 70 | +### Data Dictionary |
| 71 | + |
| 72 | +# `age_gaps.csv` |
| 73 | + |
| 74 | +|variable |class |description | |
| 75 | +|:------------------|:---------|:------------------| |
| 76 | +|movie_name |character |Name of the film | |
| 77 | +|release_year |integer |Release year | |
| 78 | +|director |character |Director of the film| |
| 79 | +|age_difference |integer |Age difference between the characters in whole years | |
| 80 | +|couple_number |integer |An identifier for the couple in case multiple couples are listed for this film | |
| 81 | +|actor_1_name |character |The name of the older actor in this couple| |
| 82 | +|actor_2_name |character |The name of the younger actor in this couple| |
| 83 | +|character_1_gender |character |The gender of the older character, as identified by the person who submitted the data for this couple| |
| 84 | +|character_2_gender |character |The gender of the younger character, as identified by the person who submitted the data for this couple| |
| 85 | +|actor_1_birthdate |date |The birthdate of the older member of the couple| |
| 86 | +|actor_2_birthdate |date |The birthdate of the younger member of the couple| |
| 87 | +|actor_1_age |integer |The age of the older actor when the film was released| |
| 88 | +|actor_2_age |integer |The age of the younger actor when the film was released| |
| 89 | + |
| 90 | + |
| 91 | +### Cleaning Script |
| 92 | + |
| 93 | +```r |
| 94 | +library(tidyverse) |
| 95 | +library(here) |
| 96 | +library(janitor) |
| 97 | + |
| 98 | +age_gaps <- read_csv( |
| 99 | + "http://hollywoodagegap.com/movies.csv", |
| 100 | +) |> |
| 101 | + clean_names() |
| 102 | + |
| 103 | +glimpse(age_gaps) |
| 104 | + |
| 105 | +# Quickly check that the columns make sense. |
| 106 | +length(vctrs::vec_cast(age_gaps$release_year, integer())) == nrow(age_gaps) |
| 107 | +length(vctrs::vec_cast(age_gaps$age_difference, integer())) == nrow(age_gaps) |
| 108 | +unique(age_gaps$actor_1_gender) |
| 109 | +!any(is.na(as.Date(age_gaps$actor_1_birthdate))) |
| 110 | +length(vctrs::vec_cast(age_gaps$actor_1_age, integer())) == nrow(age_gaps) |
| 111 | +unique(age_gaps$actor_2_gender) |
| 112 | +!any(is.na(as.Date(age_gaps$actor_2_birthdate))) |
| 113 | +length(vctrs::vec_cast(age_gaps$actor_2_age, integer())) == nrow(age_gaps) |
| 114 | + |
| 115 | +# Formally set the dates to dates. |
| 116 | +age_gaps <- age_gaps |> |
| 117 | + mutate( |
| 118 | + across( |
| 119 | + ends_with("birthdate"), |
| 120 | + as.Date |
| 121 | + ) |
| 122 | + ) |
| 123 | + |
| 124 | +# Try to get a better understanding of the "gender" columns. |
| 125 | +count(age_gaps, actor_1_gender) |
| 126 | +count(age_gaps, actor_2_gender) |
| 127 | + |
| 128 | +# The order of the characters doesn't seem to be consistent |
| 129 | +age_gaps |> |
| 130 | + summarize( |
| 131 | + p_1_older = mean(actor_1_age > actor_2_age), |
| 132 | + p_1_male = mean(actor_1_gender == "man"), |
| 133 | + p_1_female_2_male = mean(actor_1_gender == "woman" & actor_2_gender == "man"), |
| 134 | + p_1_first_alpha = mean(actor_1_name < actor_2_name) |
| 135 | + ) |
| 136 | + |
| 137 | +# For the most part, they put the man first if there's a man in the couple. It |
| 138 | +# doesn't look like there's a strict rule, though. But beware: Some movies have |
| 139 | +# more than 1 couple! Let's use all that to rebuild the data, always putting the |
| 140 | +# older character first. |
| 141 | +age_gaps <- age_gaps |> |
| 142 | + mutate( |
| 143 | + couple_number = row_number(), |
| 144 | + .by = "movie_name" |
| 145 | + ) |> |
| 146 | + pivot_longer( |
| 147 | + cols = starts_with(c("actor_1_", "actor_2_")), |
| 148 | + names_to = c(NA, NA, ".value"), |
| 149 | + names_sep = "_" |
| 150 | + ) |> |
| 151 | + # Put the older actor first. |
| 152 | + arrange(desc(age_difference), movie_name, birthdate) |> |
| 153 | + # While we have it pivoted, correct Elliot Page's name. I don't know if other |
| 154 | + # actors are similarly deadnamed, but at least we can fix this one. Note that |
| 155 | + # the *characters* played by Elliot in these particular films were women, so |
| 156 | + # I'll leave the gender as-is. |
| 157 | + mutate( |
| 158 | + name = case_match( |
| 159 | + name, |
| 160 | + "Ellen Page" ~ "Elliot Page", |
| 161 | + .default = name |
| 162 | + ) |
| 163 | + ) |> |
| 164 | + mutate( |
| 165 | + position = row_number(), |
| 166 | + .by = c("movie_name", "couple_number") |
| 167 | + ) |> |
| 168 | + pivot_wider( |
| 169 | + names_from = "position", |
| 170 | + names_glue = "actor_{position}_{.value}", |
| 171 | + values_from = c("name", "gender", "birthdate", "age") |
| 172 | + ) |
| 173 | + |
| 174 | +# The gender isn't really the actor so much as it is the character. Let's |
| 175 | +# correct that. |
| 176 | +age_gaps <- age_gaps |> |
| 177 | + rename( |
| 178 | + "character_1_gender" = "actor_1_gender", |
| 179 | + "character_2_gender" = "actor_2_gender" |
| 180 | + ) |
| 181 | + |
| 182 | +glimpse(age_gaps) |
| 183 | + |
| 184 | +# Save the data. |
| 185 | +write_csv( |
| 186 | + age_gaps, |
| 187 | + here::here( |
| 188 | + "data", "2023", "2023-02-14", |
| 189 | + "age_gaps.csv" |
| 190 | + ) |
| 191 | +) |
| 192 | +``` |
0 commit comments