Challenge 7

challenge_7
abc_poll
Visualizing Multiple Dimensions
Author

Tenzin Latoe

Published

July 16, 2023

library(tidyverse)
library(ggplot2)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Challenge Overview

Today’s challenge is to:

  1. read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
  2. tidy data (as needed, including sanity checks)
  3. mutate variables as needed (including sanity checks)
  4. Recreate at least two graphs from previous exercises, but introduce at least one additional dimension that you omitted before using ggplot functionality (color, shape, line, facet, etc) The goal is not to create unneeded chart ink (Tufte), but to concisely capture variation in additional dimensions that were collapsed in your earlier 2 or 3 dimensional graphs.
  • Explain why you choose the specific graph type
  1. If you haven’t tried in previous weeks, work this week to make your graphs “publication” ready with titles, captions, and pretty axis labels and other viewer-friendly features

R Graph Gallery is a good starting point for thinking about what information is conveyed in standard graph types, and includes example R code. And anyone not familiar with Edward Tufte should check out his fantastic books and courses on data visualizaton.

(be sure to only include the category tags for the data you use!)

Read in data

Read in one (or more) of the following datasets, using the correct R package and command.

  • Eggs ⭐
eggs <- read_csv("_data/eggs_tidy.csv")
head(eggs)

Briefly describe the data

The Eggs data set shows the price of large half dozen, large dozen, extra large half dozen, and extra large dozen eggs. The report breaks down the results per month from January 2004 till December 2013. I plan to pivot the data to reorganize the structure of the data so that it can be tidier for analysis.

Tidy Data (as needed)

eggs_clean <- eggs %>% 
  mutate(Date= ym(str_c(year, month, sep ="-"))) %>% 
  select(3:7)
head(eggs_clean)
longer<- pivot_longer(eggs, cols=c(-month,-year),
                     names_to = "package",
                     values_to = "price")
longer

Visualization with Multiple Dimensions

ggplot(longer, aes(price, fill = package)) + geom_bar() +
  theme_minimal() +
  labs(title = "Packages by price ", y = "Price", x = "Package")