Skip to content

Instantly share code, notes, and snippets.

@vanhien13
Forked from cdesante/basicmap.r
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save vanhien13/2e24b1b12c333f6a6211 to your computer and use it in GitHub Desktop.

Select an option

Save vanhien13/2e24b1b12c333f6a6211 to your computer and use it in GitHub Desktop.

Revisions

  1. @cdesante cdesante created this gist Dec 10, 2012.
    26 changes: 26 additions & 0 deletions basicmap.r
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    doInstall <- TRUE
    toInstall <- c("maps", "ggplot2")
    if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
    lapply(toInstall, library, character.only = TRUE)
    library(ggplot2)
    library(maps)

    Prison <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/prison.csv")
    head(Prison)

    all_states <- map_data("state")
    all_states
    head(all_states)
    Prison$region <- Prison$stateName
    Total <- merge(all_states, Prison, by="region")
    head(Total)
    Total <- Total[Total$region!="district of columbia",]



    p <- ggplot()
    p <- p + geom_polygon(data=Total, aes(x=long, y=lat, group = group, fill=Total$bwRatio),colour="white"
    ) + scale_fill_continuous(low = "thistle2", high = "darkred", guide="colorbar")
    P1 <- p + theme_bw() + labs(fill = "Black to White Incarceration Rates \n Weighted by Relative Population"
    ,title = "State Incarceration Rates by Race, 2010", x="", y="")
    P1 + scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border = element_blank())