AE 08: Data Types

Application exercise

Packages

We will use the tidyverse package in this application exercise.

── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Data

The data come from https://www.usclimatedata.com/climate/durham/north-carolina/united-states/usnc0192 and are stored as durham-climate.csv in the data folder.

durham_climate <- read_csv("data/durham-climate.csv")
Rows: 12 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): month
dbl (3): avg_high_f, avg_low_f, precipitation_in

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
durham_climate
# A tibble: 12 × 4
   month     avg_high_f avg_low_f precipitation_in
   <chr>          <dbl>     <dbl>            <dbl>
 1 January           49        28             4.45
 2 February          53        29             3.7 
 3 March             62        37             4.69
 4 April             71        46             3.43
 5 May               79        56             4.61
 6 June              85        65             4.02
 7 July              89        70             3.94
 8 August            87        68             4.37
 9 September         81        60             4.37
10 October           71        47             3.7 
11 November          62        37             3.39
12 December          53        30             3.43

Question: What data types are each of these columns?

Factor Reordering

Let’s talk about the following plot:

ggplot(
  durham_climate, 
  aes(x = month, y = avg_high_f, group = 1)
  ) +
  geom_line() +
  geom_point(
    shape = "circle filled", size = 2,
    color = "black", fill = "white", stroke = 1
  ) +
  labs(
    x = "Month",
    y = "Average high temperature (F)",
    title = "Durham climate"
  )

What is wrong here?

Let’s fix the plot by re-ordering our factors:

# add code here