Manuel Martinez
22/11/2020
Description: This data set contains statistics, in arrests per 100,000 residents for assault, murder, and rape in each of the 50 US states in 1973. Also given is the percent of the population living in urban areas.
Format: A data frame with 50 observations on 4 variables.
summary(USArrests)
Murder Assault UrbanPop Rape
Min. : 0.800 Min. : 45.0 Min. :32.00 Min. : 7.30
1st Qu.: 4.075 1st Qu.:109.0 1st Qu.:54.50 1st Qu.:15.07
Median : 7.250 Median :159.0 Median :66.00 Median :20.10
Mean : 7.788 Mean :170.8 Mean :65.54 Mean :21.23
3rd Qu.:11.250 3rd Qu.:249.0 3rd Qu.:77.75 3rd Qu.:26.18
Max. :17.400 Max. :337.0 Max. :91.00 Max. :46.00
inputVar <- 'Rape'; inputBin <- 25; histVal <- USArrests[, inputVar]
hist(histVal, breaks = seq(min(histVal), max(histVal), length.out = inputBin+1),
xlab = inputVar, main = paste('Distribution of', inputVar),
col = 'darkgray', border = 'white')
library(ggplot2)
scatX <- 'Murder'; scatY <- 'Rape'; scatC <- 'UrbanPop'
ggplot(data = USArrests, aes(x = Murder, y = Rape, color = UrbanPop)) +
geom_point() + xlab(scatX) + ylab(scatY) + labs(colour = scatC) +
ggtitle(paste('Scatter plot of', scatX, 'vs', scatY)) +
theme(plot.title = element_text(hjust = 0.5))