library(tidycensus)
library(tidyverse) #need to use current development version
library(ggrepel) #need to use current development version
census_api_key("enter your api key here", install = TRUE, overwrite = TRUE)
readRenviron("~/.Renviron")
v15 <- load_variables(2016, "acs5", cache = TRUE)
vt <- get_acs(geography = "county",variables = c(medincome = "B19013_001"))
vt <-subset(vt,GEOID < 72001)
pos <- position_jitter(height = 120, seed = 1)
vt %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(
shape = 21,
size = 4,
fill = "white",
stroke = 1,
position = pos
) +
labs(title = "Median Household Income by County",
subtitle = "2012-2016 American Community Survey, n = 3,137",
y = NULL,
x = NULL) +
theme_classic() +
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
geom_text_repel(data = subset(vt,
NAME == "Lake County, Illinois" |
NAME == "DeKalb County, Illinois"),
nudge_y = -500,
nudge_x = 20000,
aes(label = NAME))+
geom_text_repel(data = subset(vt, NAME == "McCreary County, Kentucky"),
nudge_y = 500,
nudge_x = 200,
aes(label = NAME))+
geom_text_repel(data = subset(vt, NAME == "Loudoun County, Virginia"),
nudge_y = -1000,
nudge_x = -500,
aes(label = NAME)) +
geom_point(
shape = 21,
size = 4,
stroke = 1,
fill = "white",
position = pos
) +
geom_point(
data = subset(vt, NAME == "Lake County, Illinois"),
shape = 21,
size = 6,
fill = "red",
stroke = 1,
position = pos
) +
scale_y_discrete(expand = c(.05, .05)) +
theme(axis.text.x = element_text(size = 12,
colour = "black")) + theme(plot.subtitle = element_text(size = 18,
colour = "black"), plot.title = element_text(size = 24))
ggsave(
"median income figure.png",
height = 9,
width = 16,
units = "in",
dpi = 300)
library(tidyverse) #need to use current development version
library(ggrepel) #need to use current development version
census_api_key("enter your api key here", install = TRUE, overwrite = TRUE)
readRenviron("~/.Renviron")
v15 <- load_variables(2016, "acs5", cache = TRUE)
vt <- get_acs(geography = "county",variables = c(medincome = "B19013_001"))
vt <-subset(vt,GEOID < 72001)
pos <- position_jitter(height = 120, seed = 1)
vt %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(
shape = 21,
size = 4,
fill = "white",
stroke = 1,
position = pos
) +
labs(title = "Median Household Income by County",
subtitle = "2012-2016 American Community Survey, n = 3,137",
y = NULL,
x = NULL) +
theme_classic() +
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
geom_text_repel(data = subset(vt,
NAME == "Lake County, Illinois" |
NAME == "DeKalb County, Illinois"),
nudge_y = -500,
nudge_x = 20000,
aes(label = NAME))+
geom_text_repel(data = subset(vt, NAME == "McCreary County, Kentucky"),
nudge_y = 500,
nudge_x = 200,
aes(label = NAME))+
geom_text_repel(data = subset(vt, NAME == "Loudoun County, Virginia"),
nudge_y = -1000,
nudge_x = -500,
aes(label = NAME)) +
geom_point(
shape = 21,
size = 4,
stroke = 1,
fill = "white",
position = pos
) +
geom_point(
data = subset(vt, NAME == "Lake County, Illinois"),
shape = 21,
size = 6,
fill = "red",
stroke = 1,
position = pos
) +
scale_y_discrete(expand = c(.05, .05)) +
theme(axis.text.x = element_text(size = 12,
colour = "black")) + theme(plot.subtitle = element_text(size = 18,
colour = "black"), plot.title = element_text(size = 24))
ggsave(
"median income figure.png",
height = 9,
width = 16,
units = "in",
dpi = 300)