|
| 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 | +# Ravelry Yarn |
| 32 | + |
| 33 | +The data this week comes from [ravelry.com](https://www.ravelry.com/yarns/) by way of [Alice Walsh](https://github.com/awalsh17). |
| 34 | + |
| 35 | +Also see the [{ravelRy}](https://www.kaylinpavlik.com/introducing-new-r-package-ravelry/) R package by Kaylin Pavlik. |
| 36 | + |
| 37 | +> Ravelry describes itself as a social networking and organizational tool for knitters, crocheters, designers, spinners, weavers and dyers. |
| 38 | +
|
| 39 | +### Get the data here |
| 40 | + |
| 41 | +```{r} |
| 42 | +# Get the Data |
| 43 | +
|
| 44 | +# Read in with tidytuesdayR package |
| 45 | +# Install from CRAN via: install.packages("tidytuesdayR") |
| 46 | +# This loads the readme and all the datasets for the week of interest |
| 47 | +
|
| 48 | +# Either ISO-8601 date or year/week works! |
| 49 | +
|
| 50 | +tuesdata <- tidytuesdayR::tt_load('2022-10-11') |
| 51 | +tuesdata <- tidytuesdayR::tt_load(2022, week = 41) |
| 52 | +
|
| 53 | +yarn <- tuesdata$yarn |
| 54 | +
|
| 55 | +# Or read in the data manually |
| 56 | +
|
| 57 | +yarn <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-10-11/yarn.csv') |
| 58 | +
|
| 59 | +``` |
| 60 | +### Data Dictionary |
| 61 | + |
| 62 | +# `yarn.csv` |
| 63 | + |
| 64 | +|variable |class |description | |
| 65 | +|:-------------------------|:---------|:-----------| |
| 66 | +|discontinued |logical | discontinued true/false | |
| 67 | +|gauge_divisor |double | gauge divisor - The number of inches that equal min_gauge to max_gauge stitches | |
| 68 | +|grams |double | Unit weight in grams | |
| 69 | +|id |double | id | |
| 70 | +|machine_washable |logical | machine washable true/false | |
| 71 | +|max_gauge |double | max gauge - The max number of stitches that equal gauge_divisor | |
| 72 | +|min_gauge |double | min gauge - The min number of stitches that equal gauge_divisor | |
| 73 | +|name |character | name | |
| 74 | +|permalink |character | permalink | |
| 75 | +|rating_average |double | rating average - The average rating out of 5 | |
| 76 | +|rating_count |double | rating count | |
| 77 | +|rating_total |double | rating total | |
| 78 | +|texture |character | texture - Texture free text | |
| 79 | +|thread_size |character | thread size | |
| 80 | +|wpi |double | wraps per inch | |
| 81 | +|yardage |double | yardage | |
| 82 | +|yarn_company_name |character | Yarn company name | |
| 83 | +|yarn_weight_crochet_gauge |logical | Yarn weight crochet gauge - Crochet gauge for the yarn weight category | |
| 84 | +|yarn_weight_id |double | Yarn weight ID - Identifier for the yarn weight category | |
| 85 | +|yarn_weight_knit_gauge |character | Yarn weight knit gauge - Knit guage for the yarn weight category | |
| 86 | +|yarn_weight_name |character | Yarn weight name - Name for the yarn weight category | |
| 87 | +|yarn_weight_ply |double | Yarn weight ply - Ply for the yarn weight category | |
| 88 | +|yarn_weight_wpi |character | Yarn weight wraps per inch - Wraps per inch for the yarn weight category | |
| 89 | +|texture_clean |character | Texture clean - Texture with some light text cleaning | |
| 90 | + |
| 91 | +### Cleaning Script |
| 92 | + |
| 93 | +Clean script source: <https://github.com/awalsh17/ravelry_yarns> |
| 94 | + |
| 95 | +```r |
| 96 | +# Call to ravelry API |
| 97 | + |
| 98 | +library(dplyr) |
| 99 | +library(httr) |
| 100 | +library(jsonlite) |
| 101 | + |
| 102 | +# get the information on 100,000 yarns ------- |
| 103 | +# iterate over all pages (1000 results per) 100,000 total, api user/pass was saved to env |
| 104 | + |
| 105 | +pages <- c(1:100) |
| 106 | + |
| 107 | +resp <- purrr::map(pages, ~httr::GET( |
| 108 | + url = paste0("https://api.ravelry.com/yarns/search.json?sort=best&page_size=1000&page=", .x), |
| 109 | + authenticate(Sys.getenv("RAVELRY_API_USER"), Sys.getenv("RAVELRY_API_PASS")))) |
| 110 | + |
| 111 | +# first item is the yarn data |
| 112 | + |
| 113 | +yarn_all <- purrr::map_dfr(resp, ~fromJSON(content(.x, as = "text"))[[1]]) |
| 114 | + |
| 115 | +# second is the paginator - 100 pages |
| 116 | + |
| 117 | +# write out raw |
| 118 | + |
| 119 | +saveRDS(yarn_all, "data/yarn_raw.Rds") |
| 120 | + |
| 121 | +# unnest the data frame, remove first_photo and personal_attributes |
| 122 | + |
| 123 | +yarn_all <- tidyr::unnest(yarn_all, yarn_weight, names_sep = "_") %>% |
| 124 | + select(-first_photo, -personal_attributes) |
| 125 | + |
| 126 | +# yarn_weight_min_gauge and yarn_weight_max_gauge are always missing |
| 127 | + |
| 128 | +yarn_all <- select(yarn_all, -yarn_weight_max_gauge, -yarn_weight_min_gauge) |
| 129 | + |
| 130 | +# clean the texture variable |
| 131 | + |
| 132 | +yarn_all$texture_clean <- stringr::str_trim(yarn_all$texture) |
| 133 | +yarn_all$texture_clean <- stringr::str_to_lower(yarn_all$texture_clean) |
| 134 | + |
| 135 | +# write out the final csv |
| 136 | + |
| 137 | +write.csv(yarn_all, "data/yarn.csv", row.names = FALSE) |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +# Query for more yarn information ----- |
| 143 | + |
| 144 | +# need to split request up into chunks of 100 |
| 145 | + |
| 146 | +chunks <- dplyr::ntile(1:100000, 1000) |
| 147 | +yarn_ids <- purrr::map( |
| 148 | + 1:1000, |
| 149 | + ~paste(unique(yarn_all$id)[chunks == .x], collapse = "+")) |
| 150 | + |
| 151 | +resp <- purrr::map( |
| 152 | + yarn_ids, |
| 153 | + ~httr::GET(url = paste0("https://api.ravelry.com/yarns.json?ids=", .x), |
| 154 | + authenticate(Sys.getenv("RAVELRY_API_USER"), Sys.getenv("RAVELRY_API_PASS")))) |
| 155 | + |
| 156 | +yarn_json <- purrr::map( |
| 157 | + resp, |
| 158 | + ~parse_json(content(.x, as = "text"), simplifyVector = TRUE)$yarns) |
| 159 | +yarn_json <- unlist(yarn_json, recursive = FALSE) |
| 160 | + |
| 161 | +# yarn_fibers with have more than one row per yarn |
| 162 | + |
| 163 | +yarn_fibers <- purrr::map_dfr(yarn_json, ~.x[["yarn_fibers"]], .id = "yarn_id") %>% |
| 164 | + tidyr::unnest(fiber_type, names_sep = "_") %>% |
| 165 | + select(-fiber_category, -id) %>% |
| 166 | + rename(id = yarn_id) # make primary key id for yarn |
| 167 | + |
| 168 | +# yarn_attributes have more than one row per yarn (care, color, dye) |
| 169 | + |
| 170 | +yarn_attributes <- purrr::map_dfr(yarn_json, ~.x[["yarn_attributes"]], .id = "yarn_id") %>% |
| 171 | + tidyr::unnest(yarn_attribute_group, names_sep = "_") %>% |
| 172 | + select(-id, -yarn_attribute_group_id) %>% |
| 173 | + rename(id = yarn_id) # make primary key id for yarn |
| 174 | + |
| 175 | +# this has all the possible values for the yarn_attribute_group |
| 176 | + |
| 177 | +yarn_attribute_groups <- httr::GET( |
| 178 | + url = "https://api.ravelry.com/yarn_attributes/groups.json", |
| 179 | + authenticate(Sys.getenv("RAVELRY_API_USER"), Sys.getenv("RAVELRY_API_PASS"))) |
| 180 | + |
| 181 | +yarn_attribute_groups <- fromJSON(content(yarn_attribute_groups, as = "text"))[[1]] %>% |
| 182 | + tidyr::unnest(yarn_attributes, names_sep = "_") %>% |
| 183 | + select(-children) # for construction attributes, just remove for here |
| 184 | + |
| 185 | +# write out yarn_fibers and yarn_attributes |
| 186 | + |
| 187 | +write.csv(yarn_fibers, "data/yarn_fibers.csv", row.names = FALSE) |
| 188 | +write.csv(yarn_attribute_groups, "data/yarn_attribute_groups.csv", row.names = FALSE) |
| 189 | +write.csv(yarn_attributes, "data/yarn_attributes.csv", row.names = FALSE) |
| 190 | +``` |
0 commit comments