Time to try your hand at the data visualization techniques we went over earlier tonight. Use R to run the data retrieval code, which will download and open, on your computer, the same data file used in the Basic Data Visualization in R guide. Then, recreate each of the four visualizations shown below. You may leave after showing me each of the data visualizations on your computer.
# Read the data from the web
FetchedData <-
read.csv("https://drkblake.com/wp-content/uploads/2023/11/DataWrangling.csv")
# Save the data on your computer
write.csv(FetchedData, "DataWrangling.csv", row.names = FALSE)
# remove the data from the environment
rm (FetchedData)
# Installing required packages
if (!require("tidyverse"))
install.packages("tidyverse")
library(tidyverse)
# Read the data
mydata <- read.csv("DataWrangling.csv")
# Create a continuous "Density" variable measuring
# households per square mile, then a two-level and
# a three-level categorical version
mydata <- mydata %>%
mutate(Density = Households / Land_area) %>%
mutate(Density_2 = cut_number(Density, n = 2)) %>% mutate(Density_3 = cut_number(Density, n = 3))
mydata <- mydata %>%
mutate(
Density_2 = case_when(
Density_2 == "[7.35,28.6]" ~ "Low density",
Density_2 == "(28.6,583]" ~ "High density",
.default = "Error"
)
)
mydata <- mydata %>%
mutate(
Density_3 = case_when(
Density_3 == "[7.35,21]" ~ "Low density",
Density_3 == "(21,40.4]" ~ "Intermediate density",
Density_3 == "(40.4,583]" ~ "High density",
.default = "Error"
)
)
# Re-save the data on your computer
write.csv(mydata, "DataWrangling.csv", row.names = FALSE)
Make this, using Pct_College
and
Med_HH_Income
.
Make this, using Pct_College
,
Med_HH_Income
, and Density_2
.
Make this, using Density_3
and
Region
Make this, using Pct_College
: