
“Computational Literacy”
“Data Literacy”

Data
Average student engagement scores
| Class | Type | City | County |
|---|---|---|---|
| Special Ed. | Charter | 643 | 793 |
| Special Ed. | Public | 735 | 928 |
| General Ed. | Charter | 590 | 724 |
| General Ed. | Public | 863 | 662 |
Information

Encode data:
#> City County School
#> 1 643 793 Special Ed., Charter
#> 2 735 928 Special Ed., Public
#> 3 590 724 General Ed., Charter
#> 4 863 662 General Ed., Public
Re-format data for plotting:
#> # A tibble: 8 × 3
#> School Location Engagement
#> <chr> <chr> <dbl>
#> 1 Special Ed., Charter City 643
#> 2 Special Ed., Charter County 793
#> 3 Special Ed., Public City 735
#> 4 Special Ed., Public County 928
#> 5 General Ed., Charter City 590
#> 6 General Ed., Charter County 724
#> 7 General Ed., Public City 863
#> 8 General Ed., Public County 662
Directly label figure:

Remove unnecessary axes, change colors, fix labels:

Clean the data
data <- data.frame(
City = c(643, 735, 590, 863),
County = c(793, 928, 724, 662),
School = c(
"Special Ed., Charter", "Special Ed., Public",
"General Ed., Charter", "General Ed., Public"
),
Highlight = c(0, 0, 0, 1)
) %>%
pivot_longer(
cols = c(City, County),
names_to = "Location",
values_to = "Engagement"
) %>%
mutate(
Location = fct_relevel(Location, c("City", "County")),
Highlight = as.factor(Highlight),
x = ifelse(Location == "County", 1, 0)
)Make the plot
plot <- ggplot(data, aes(
x = x, y = Engagement, group = School, color = Highlight
)) +
geom_point() +
geom_line() +
scale_color_manual(values = c("#757575", "#ed573e")) +
labs(
x = "Sex", y = "Engagement",
title = "County general-ed classes have low engagement"
) +
scale_x_continuous(
limits = c(-1.2, 1.2),
labels = c("City", "County"), breaks = c(0, 1)
) +
geom_text_repel(aes(label = Engagement), size = 5) +
theme_cowplot() +
background_grid(major = "x") +
theme(legend.position = "none")



You should be able to:
Why quiz at all? The “retrieval effect” - basically, you have to practice remembering things, otherwise your brain won’t remember them (see the book “Make It Stick: The Science of Successful Learning”)
Undergrads: Teams of 3 - 4 students
Grads: Teams of 2 students
| Item | Due Date |
|---|---|
| Proposal | Sep 20 |
| Initial Report | Nov 01 |
| Final Report | Dec 06 |
| Presentation | Dec 08 |
| Item | Weight | Notes |
|---|---|---|
| Participation / Attendance | 7 % | (Yes, I take attendance) |
| Weekly HW | 11 % | Weekly assignment, lowest dropped |
| Quizzes | 10 % | 5 quizzes, lowest dropped |
| Mini Project 1 | 9 % | Individual assignments |
| Mini Project 2 | 9 % | |
| Mini Project 3 | 9 % | |
| Final Project: Proposal | 6 % | Team project |
| Final Project: Progress Report | 6 % | |
| Final Project: Report | 17 % | |
| Final Project: Presentation | 6 % | |
| Final Interview | 10 % | Individual interview |

“Plagiarism is trying to pass someone else’s work off as your own. Copying is about reverse-engineering.”
– Austin Kleon, from Steal Like An Artist
05:00
quarto_demo.qmd
Add table of contents, change theme
More on themes at https://quarto.org/docs/output-formats/html-themes.html
normal text_italic text_*italic text***bold text*****bold italic text***~~strikethrough~~`code text`code textSimple url link to another site:
Produces this:
The sum of 3 and 4 is 7
…will produce this when rendered:
#> Rows: 4
#> Columns: 8
#> $ species <fct> Adelie, Adelie, Adelie, Adelie
#> $ island <fct> Torgersen, Torgersen, Torgersen, Torgersen
#> $ bill_length_mm <dbl> 39.1, 39.5, 40.3, NA
#> $ bill_depth_mm <dbl> 18.7, 17.4, 18.0, NA
#> $ flipper_length_mm <int> 181, 186, 195, NA
#> $ body_mass_g <int> 3750, 3800, 3250, NA
#> $ sex <fct> male, female, female, NA
#> $ year <int> 2007, 2007, 2007, 2007
Control what chunks output using options
All options here
By default, code chunks print code + output
setup chunk 🌍file.path() — relative to the folder you opened| File type | Function | Library |
|---|---|---|
.csv |
read_csv() |
readr |
.txt |
read.table() |
utils |
.xlsx |
read_excel() |
readxl |
Read in .csv files with read_csv():
#> # A tibble: 6 × 4
#> region state year milk_produced
#> <chr> <chr> <dbl> <dbl>
#> 1 Northeast Maine 1970 619000000
#> 2 Northeast New Hampshire 1970 356000000
#> 3 Northeast Vermont 1970 1970000000
#> 4 Northeast Massachusetts 1970 658000000
#> 5 Northeast Rhode Island 1970 75000000
#> 6 Northeast Connecticut 1970 661000000
Read in .txt files with read.table():
Read in .txt files with read.table():
#> year no_smoothing loess
#> 1 1880 -0.15 -0.08
#> 2 1881 -0.07 -0.12
#> 3 1882 -0.10 -0.15
#> 4 1883 -0.16 -0.19
#> 5 1884 -0.27 -0.23
#> 6 1885 -0.32 -0.25
Read in .xlsx files with read_excel():
#> Rows: 6
#> Columns: 10
#> $ Year <chr> NA, NA, "1995", "1996", "1997", "1998"
#> $ China <chr> "Megawatts", NA, "NA", "NA", "NA", "NA"
#> $ Taiwan <chr> NA, NA, "NA", "NA", "NA", "NA"
#> $ Japan <dbl> NA, NA, 16.4, 21.2, 35.0, 49.0
#> $ Malaysia <chr> NA, NA, "NA", "NA", "NA", "NA"
#> $ Germany <chr> NA, NA, "NA", "NA", "NA", "NA"
#> $ `South Korea` <chr> NA, NA, "NA", "NA", "NA", "NA"
#> $ `United States` <dbl> NA, NA, 34.75, 38.85, 51.00, 53.70
#> $ Others <chr> NA, NA, "NA", "NA", "NA", "NA"
#> $ World <dbl> NA, NA, 77.6, 88.6, 125.8, 154.9
Read in .xlsx files with read_excel():
#> Rows: 6
#> Columns: 10
#> $ Year <dbl> 1995, 1996, 1997, 1998, 1999, 2000
#> $ China <chr> "NA", "NA", "NA", "NA", "NA", "2.5"
#> $ Taiwan <chr> "NA", "NA", "NA", "NA", "NA", "NA"
#> $ Japan <dbl> 16.4, 21.2, 35.0, 49.0, 80.0, 128.6
#> $ Malaysia <chr> "NA", "NA", "NA", "NA", "NA", "NA"
#> $ Germany <chr> "NA", "NA", "NA", "NA", "NA", "22.5"
#> $ `South Korea` <chr> "NA", "NA", "NA", "NA", "NA", "NA"
#> $ `United States` <dbl> 34.75, 38.85, 51.00, 53.70, 60.80, 75.00
#> $ Others <chr> "NA", "NA", "NA", "NA", "NA", "48.200000000000017"
#> $ World <dbl> 77.6, 88.6, 125.8, 154.9, 201.3, 276.8
Open the practice.qmd file.
Write code to import the following data files from the “data” folder:
lotr_words.csv, call the data frame lotrnorth_america_bear_killings.txt, call the data frame bearsuspto_clean_energy_patents.xlsx, call the data frame patents10:00

#> # A tibble: 18 × 4
#> film race gender word_count
#> <chr> <chr> <chr> <dbl>
#> 1 The Fellowship Of The Ring Elf Female 1229
#> 2 The Fellowship Of The Ring Elf Male 971
#> 3 The Fellowship Of The Ring Hobbit Female 14
#> 4 The Fellowship Of The Ring Hobbit Male 3644
#> 5 The Fellowship Of The Ring Man Female 0
#> 6 The Fellowship Of The Ring Man Male 1995
#> 7 The Return Of The King Elf Female 183
#> 8 The Return Of The King Elf Male 510
#> 9 The Return Of The King Hobbit Female 2
#> 10 The Return Of The King Hobbit Male 2673
#> 11 The Return Of The King Man Female 268
#> 12 The Return Of The King Man Male 2459
#> 13 The Two Towers Elf Female 331
#> 14 The Two Towers Elf Male 513
#> 15 The Two Towers Hobbit Female 0
#> 16 The Two Towers Hobbit Male 2463
#> 17 The Two Towers Man Female 401
#> 18 The Two Towers Man Male 3589
Extract a column using $
Can also use brackets:
#> [1] "Elf" "Elf" "Hobbit" "Hobbit" "Man" "Man" "Elf" "Elf" "Hobbit" "Hobbit" "Man" "Man" "Elf" "Elf" "Hobbit" "Hobbit" "Man" "Man"
#> # A tibble: 18 × 1
#> race
#> <chr>
#> 1 Elf
#> 2 Elf
#> 3 Hobbit
#> 4 Hobbit
#> 5 Man
#> 6 Man
#> 7 Elf
#> 8 Elf
#> 9 Hobbit
#> 10 Hobbit
#> 11 Man
#> 12 Man
#> 13 Elf
#> 14 Elf
#> 15 Hobbit
#> 16 Hobbit
#> 17 Man
#> 18 Man
Information about the first row:
#> # A tibble: 1 × 4
#> film race gender word_count
#> <chr> <chr> <chr> <dbl>
#> 1 The Fellowship Of The Ring Elf Female 1229
Information about rows 1 & 2:
Read in the data.csv file in the “data” folder:
Now answer these questions:
stringr + dplyr + readr + ggplot2 + …
Art by Allison Horst
dplyr “verbs”| “Verb” | What it does |
|---|---|
select() |
Select columns by name |
filter() |
Keep rows that match criteria |
arrange() |
Sort rows based on column(s) |
mutate() |
Create new columns |
summarize() |
Create summary values |
tidyverse concept:%>%select()
select()Select the columns film & race
#> # A tibble: 18 × 2
#> film race
#> <chr> <chr>
#> 1 The Fellowship Of The Ring Elf
#> 2 The Fellowship Of The Ring Elf
#> 3 The Fellowship Of The Ring Hobbit
#> 4 The Fellowship Of The Ring Hobbit
#> 5 The Fellowship Of The Ring Man
#> 6 The Fellowship Of The Ring Man
#> 7 The Return Of The King Elf
#> 8 The Return Of The King Elf
#> 9 The Return Of The King Hobbit
#> 10 The Return Of The King Hobbit
#> 11 The Return Of The King Man
#> 12 The Return Of The King Man
#> 13 The Two Towers Elf
#> 14 The Two Towers Elf
#> 15 The Two Towers Hobbit
#> 16 The Two Towers Hobbit
#> 17 The Two Towers Man
#> 18 The Two Towers Man
select()Use the - sign to drop columns
#> # A tibble: 18 × 3
#> race gender word_count
#> <chr> <chr> <dbl>
#> 1 Elf Female 1229
#> 2 Elf Male 971
#> 3 Hobbit Female 14
#> 4 Hobbit Male 3644
#> 5 Man Female 0
#> 6 Man Male 1995
#> 7 Elf Female 183
#> 8 Elf Male 510
#> 9 Hobbit Female 2
#> 10 Hobbit Male 2673
#> 11 Man Female 268
#> 12 Man Male 2459
#> 13 Elf Female 331
#> 14 Elf Male 513
#> 15 Hobbit Female 0
#> 16 Hobbit Male 2463
#> 17 Man Female 401
#> 18 Man Male 3589
filter()
filter()Keep only the rows with Elf characters
#> # A tibble: 6 × 4
#> film race gender word_count
#> <chr> <chr> <chr> <dbl>
#> 1 The Fellowship Of The Ring Elf Female 1229
#> 2 The Fellowship Of The Ring Elf Male 971
#> 3 The Return Of The King Elf Female 183
#> 4 The Return Of The King Elf Male 510
#> 5 The Two Towers Elf Female 331
#> 6 The Two Towers Elf Male 513
filter()Keep only the rows with Elf or Hobbit characters
#> # A tibble: 12 × 4
#> film race gender word_count
#> <chr> <chr> <chr> <dbl>
#> 1 The Fellowship Of The Ring Elf Female 1229
#> 2 The Fellowship Of The Ring Elf Male 971
#> 3 The Fellowship Of The Ring Hobbit Female 14
#> 4 The Fellowship Of The Ring Hobbit Male 3644
#> 5 The Return Of The King Elf Female 183
#> 6 The Return Of The King Elf Male 510
#> 7 The Return Of The King Hobbit Female 2
#> 8 The Return Of The King Hobbit Male 2673
#> 9 The Two Towers Elf Female 331
#> 10 The Two Towers Elf Male 513
#> 11 The Two Towers Hobbit Female 0
#> 12 The Two Towers Hobbit Male 2463
filter()Keep only the rows with Elf or Hobbit characters
#> # A tibble: 12 × 4
#> film race gender word_count
#> <chr> <chr> <chr> <dbl>
#> 1 The Fellowship Of The Ring Elf Female 1229
#> 2 The Fellowship Of The Ring Elf Male 971
#> 3 The Fellowship Of The Ring Hobbit Female 14
#> 4 The Fellowship Of The Ring Hobbit Male 3644
#> 5 The Return Of The King Elf Female 183
#> 6 The Return Of The King Elf Male 510
#> 7 The Return Of The King Hobbit Female 2
#> 8 The Return Of The King Hobbit Male 2673
#> 9 The Two Towers Elf Female 331
#> 10 The Two Towers Elf Male 513
#> 11 The Two Towers Hobbit Female 0
#> 12 The Two Towers Hobbit Male 2463
filter()| Description | Example |
|---|---|
| Values greater than 1 | value > 1 |
| Values greater than or equal to 1 | value >= 1 |
| Values less than 1 | value < 1 |
| Values less than or equal to 1 | value <= 1 |
| Values equal to 1 | value == 1 |
| Values not equal to 1 | value != 1 |
| Values in the set c(1, 4) | value %in% c(1, 4) |
filter() and select()Keep only the rows with Elf characters that spoke more than 1000 words, then select everything but the race column
mutate()
mutate()Create a new variable, word1000 which is TRUE if the character spoke 1,000 or more words
#> # A tibble: 18 × 5
#> film race gender word_count word1000
#> <chr> <chr> <chr> <dbl> <lgl>
#> 1 The Fellowship Of The Ring Elf Female 1229 TRUE
#> 2 The Fellowship Of The Ring Elf Male 971 FALSE
#> 3 The Fellowship Of The Ring Hobbit Female 14 FALSE
#> 4 The Fellowship Of The Ring Hobbit Male 3644 TRUE
#> 5 The Fellowship Of The Ring Man Female 0 FALSE
#> 6 The Fellowship Of The Ring Man Male 1995 TRUE
#> 7 The Return Of The King Elf Female 183 FALSE
#> 8 The Return Of The King Elf Male 510 FALSE
#> 9 The Return Of The King Hobbit Female 2 FALSE
#> 10 The Return Of The King Hobbit Male 2673 TRUE
#> 11 The Return Of The King Man Female 268 FALSE
#> 12 The Return Of The King Man Male 2459 TRUE
#> 13 The Two Towers Elf Female 331 FALSE
#> 14 The Two Towers Elf Male 513 FALSE
#> 15 The Two Towers Hobbit Female 0 FALSE
#> 16 The Two Towers Hobbit Male 2463 TRUE
#> 17 The Two Towers Man Female 401 FALSE
#> 18 The Two Towers Man Male 3589 TRUE
ifelse(<condition>, <if TRUE>, <else>)#> # A tibble: 18 × 5
#> film race gender word_count word1000
#> <chr> <chr> <chr> <dbl> <lgl>
#> 1 The Fellowship Of The Ring Elf Female 1229 TRUE
#> 2 The Fellowship Of The Ring Elf Male 971 FALSE
#> 3 The Fellowship Of The Ring Hobbit Female 14 FALSE
#> 4 The Fellowship Of The Ring Hobbit Male 3644 TRUE
#> 5 The Fellowship Of The Ring Man Female 0 FALSE
#> 6 The Fellowship Of The Ring Man Male 1995 TRUE
#> 7 The Return Of The King Elf Female 183 FALSE
#> 8 The Return Of The King Elf Male 510 FALSE
#> 9 The Return Of The King Hobbit Female 2 FALSE
#> 10 The Return Of The King Hobbit Male 2673 TRUE
#> 11 The Return Of The King Man Female 268 FALSE
#> 12 The Return Of The King Man Male 2459 TRUE
#> 13 The Two Towers Elf Female 331 FALSE
#> 14 The Two Towers Elf Male 513 FALSE
#> 15 The Two Towers Hobbit Female 0 FALSE
#> 16 The Two Towers Hobbit Male 2463 TRUE
#> 17 The Two Towers Man Female 401 FALSE
#> 18 The Two Towers Man Male 3589 TRUE
arrange()Sort the lotr data frame by word_count
#> # A tibble: 18 × 4
#> film race gender word_count
#> <chr> <chr> <chr> <dbl>
#> 1 The Fellowship Of The Ring Man Female 0
#> 2 The Two Towers Hobbit Female 0
#> 3 The Return Of The King Hobbit Female 2
#> 4 The Fellowship Of The Ring Hobbit Female 14
#> 5 The Return Of The King Elf Female 183
#> 6 The Return Of The King Man Female 268
#> 7 The Two Towers Elf Female 331
#> 8 The Two Towers Man Female 401
#> 9 The Return Of The King Elf Male 510
#> 10 The Two Towers Elf Male 513
#> 11 The Fellowship Of The Ring Elf Male 971
#> 12 The Fellowship Of The Ring Elf Female 1229
#> 13 The Fellowship Of The Ring Man Male 1995
#> 14 The Return Of The King Man Male 2459
#> 15 The Two Towers Hobbit Male 2463
#> 16 The Return Of The King Hobbit Male 2673
#> 17 The Two Towers Man Male 3589
#> 18 The Fellowship Of The Ring Hobbit Male 3644
arrange()Use the desc() function to sort in descending order
#> # A tibble: 18 × 4
#> film race gender word_count
#> <chr> <chr> <chr> <dbl>
#> 1 The Fellowship Of The Ring Hobbit Male 3644
#> 2 The Two Towers Man Male 3589
#> 3 The Return Of The King Hobbit Male 2673
#> 4 The Two Towers Hobbit Male 2463
#> 5 The Return Of The King Man Male 2459
#> 6 The Fellowship Of The Ring Man Male 1995
#> 7 The Fellowship Of The Ring Elf Female 1229
#> 8 The Fellowship Of The Ring Elf Male 971
#> 9 The Two Towers Elf Male 513
#> 10 The Return Of The King Elf Male 510
#> 11 The Two Towers Man Female 401
#> 12 The Two Towers Elf Female 331
#> 13 The Return Of The King Man Female 268
#> 14 The Return Of The King Elf Female 183
#> 15 The Fellowship Of The Ring Hobbit Female 14
#> 16 The Return Of The King Hobbit Female 2
#> 17 The Fellowship Of The Ring Man Female 0
#> 18 The Two Towers Hobbit Female 0
10:00
Read in the data.csv file in the “data” folder:
flights_fall, that contains only flights that departed in the fall semester.flights_dc, that contains only flights that flew to DC airports (Reagan or Dulles).flights_dc_carrier, that contains only flights that flew to DC airports (Reagan or Dulles) and only the columns about the month and airline.speed, in miles per hour using the time (minutes) and distance (miles) variables.NA for air_time and re-arrange the resulting data frame based on the longest air time and longest flight distance.
Concept developed by Leland Wilkinson (1999)
ggplot2 package developed by Hadley Wickham (2005)
#> # A tibble: 6 × 11
#> manufacturer model displ year cyl trans drv cty hwy fl class
#> <chr> <chr> <dbl> <int> <int> <chr> <chr> <int> <int> <chr> <chr>
#> 1 audi a4 1.8 1999 4 auto(l5) f 18 29 p compact
#> 2 audi a4 1.8 1999 4 manual(m5) f 21 29 p compact
#> 3 audi a4 2 2008 4 manual(m6) f 20 31 p compact
#> 4 audi a4 2 2008 4 auto(av) f 21 30 p compact
#> 5 audi a4 2.8 1999 6 auto(l5) f 16 26 p compact
#> 6 audi a4 2.8 1999 6 manual(m5) f 18 26 p compact
The ggplot() function initializes the plot with whatever data you’re using
The aes() function determines which variables will be mapped to the geometries
(e.g. the axes)
Use + to add geometries, e.g. geom_point() for points
Use labs() to modify most labels


15:00
Open practice.qmd
Use the mpg data frame and ggplot to create these charts


