1. Importing Data into R

Install the ISLR package, load the tidyverse and ISLR package and Wage data.

library(ISLR)
library(tidyverse)

data(Wage)
  1. Produce a scatterplot with wage on the y-axis and age on the x-axis, fill and color the points using education levels
ggplot(Wage, aes(age, wage)) + geom_point(aes(color = education, fill = education))

  1. Load the Census Term 1 File, install the Hmisc package and create a new variable called “ACT_GROUP” with the following commands.
library(Hmisc)

census_term1 <- read_csv("https://raw.githubusercontent.com/bpattizUCM/MidAIR2017/master/Census%20Term1.csv") %>%
filter(!is.na(ACT)) %>%
mutate(ACT_GROUP = cut2(ACT, g = 4))

head(census_term1 %>% select(ID, ACT, ACT_GROUP))
## # A tibble: 6 x 3
##      ID   ACT ACT_GROUP
##   <int> <int>    <fctr>
## 1     1    21   [20,23)
## 2     2    19   [12,20)
## 3     3    26   [25,35]
## 4     4    20   [20,23)
## 5     5    21   [20,23)
## 6     6    24   [23,25)

Create a boxplot of HS_GPA and ACT_GROUP. Fill by ACT_GROUP, change the x-axis label to “ACT” and the y-axis to “High School GPA”give it a title called “High School GPA by ACT”. Center the title using the followign command: theme(plot.title = element_text(hjust = 0.5))

ggplot(census_term1, aes(ACT_GROUP, HS_GPA)) + geom_boxplot(aes(fill = ACT_GROUP)) + xlab("ACT") + ylab("High School GPA") + ggtitle("High School GPA by ACT") + theme(plot.title = element_text(hjust = 0.5))

  1. Create a faceted histogram of Hours by Stype. Use a binwidth of 0.95 for the histogram.
ggplot(census_term1, aes(Hours)) + facet_wrap(~factor(Stype)) + geom_histogram(binwidth = 0.95)

  1. Create a bar plot of 1995 Enrollment with your University/College with two peer institutions. Run the following code to get the data and use row.names(College) to find the peer instituions.
data(College)

College_DF <-
  College %>%
  rownames_to_column("College") %>%
  select(College, Enroll)

Change the y-axis label to “Enrollment”. Give it the black and white theme. Create a caption to give credit to the US News and World Report.

Missouri_Publics <-
  College_DF %>%
  filter(College %in% c("Central Missouri State University", "Southwest Missouri State University", "University of Missouri at Columbia")) %>%
  mutate(College = case_when(College == "Central Missouri State University" ~ "UCM",
                             College == "Southwest Missouri State University" ~
                             "MSU",
                              College == "University of Missouri at Columbia" ~ "MU")) 

ggplot(Missouri_Publics, aes(College, Enroll, fill = College)) + geom_bar(stat = "identity") + ylab("Enrollment") + 
  theme_bw() + labs(caption ="Source: 1995 US News and World Report")