Created
August 23, 2011 14:29
-
-
Save Chicago/1165275 to your computer and use it in GitHub Desktop.
Crimes - Sample R code - Pie Chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Quick and easy way to visualize the crimes data set using open source techniques | |
##Have more ideas? Tell me about them at @ChicagoCDO | |
##All you need to do is install R at http://cran.r-project.org/ and run this file | |
install.packages("googleVis") | |
library(googleVis) | |
crimes_stage <- read.csv("http://data.cityofchicago.org/views/x2n5-8w5q/rows.csv") | |
attach(crimes_stage) | |
##remove first row with column names | |
crimes <- crimes_stage[-c(1),] | |
##create frequency table from crime | |
freq <- table(PRIMARY.DESCRIPTION) | |
##change frequency table to data frame | |
freq.data <- as.data.frame(freq) | |
pie <- gvisPieChart(freq.data,options=list(height=1200,width=1200)) | |
## Appreciate visual output | |
plot(pie) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it's a little overly complicated for purposes of demonstration to include code that automatically installs libraries, this example is cleaner:
Run
install.packages("googleVis")
and / orinstall.packages("jsonlite")
if the libraries are missing.