Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created September 29, 2011 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramnathv/1251456 to your computer and use it in GitHub Desktop.
Save ramnathv/1251456 to your computer and use it in GitHub Desktop.
Map of US Auto Plant Locations
# LOAD LIBRARIES ---------------------------------------------------------------
library(ggplot2)
library(maps)
# LOAD DATA --------------------------------------------------------------------
# read data and add column names
auto_plants = read.csv('Data.csv', as.is = TRUE,
col.names = c('location', 'firm', 'lat', 'long', 'Production', 'temparature'))
# classify firm as others if total plants < 5
auto_plants = ddply(auto_plants, .(firm), mutate,
num_plants = length(firm),
Firm = ifelse(num_plants < 5, 'OTHERS', firm)
)
# get us state map data
us_states = map_data('state')
# construct map of auto plant locations
auto_map = ggplot(us_states, aes(x = long, y = lat)) +
geom_polygon(aes(group = group), fill = 'gray80', colour = 'gray') +
geom_point(data = auto_plants, aes(size = Production, colour = Firm),
alpha = 0.7) +
scale_area(to = c(2, 8)) +
xlab(NULL) + ylab(NULL) +
theme_bw() +
coord_cartesian(xlim = c(-130, -55)) +
opts(
legend.position = c(0.90, 0.40),
panel.border = theme_blank(),
panel.grid.major = theme_blank(),
panel.grid.minor = theme_blank(),
axis.text.x = theme_blank(),
axis.text.y = theme_blank(),
axis.ticks = theme_blank(),
plot.title = theme_text(hjust = 0.1, vjust = 1, face = 'bold', size = 20),
title = 'LOCATION OF AUTO PLANTS IN UNITED STATES')
print(auto_map)
ggsave('auto_plant_map.pdf', auto_map, width = 10, height = 7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment