library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.4
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
data("USArrests")
state_name_to_abbrev <- data.frame(
abbrev = state.abb,
name = state.name
)
head(USArrests)
## Murder Assault UrbanPop Rape
## Alabama 13.2 236 58 21.2
## Alaska 10.0 263 48 44.5
## Arizona 8.1 294 80 31.0
## Arkansas 8.8 190 50 19.5
## California 9.0 276 91 40.6
## Colorado 7.9 204 78 38.7
arrests <- USArrests %>%
tibble::rownames_to_column(var = "name") %>%
inner_join(state_name_to_abbrev) %>%
select(name, abbrev, everything()) %>%
mutate(name = tolower(name))
## Joining, by = "name"
## Warning: Column `name` joining character vector and factor, coercing into
## character vector
## Warning: package 'bindrcpp' was built under R version 3.4.4
states <- map_data("state")
states %>%
inner_join(arrests, by = c("region" = "name")) %>%
ggplot() +
geom_polygon(aes(x = long, y = lat, fill = Murder , group = group), color = "white") +
coord_fixed(1.3) +
guides(fill=FALSE) +
theme_void()# do this to leave off the color legend
GGally::ggpairs(select_if(arrests, is.numeric))
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Pinterest
Email