Interactive Morris Pie Charts
This page explores the creation of simple interactive charts created from unweighted data from The Pew Research Center's American Life Project, "The Social Side of the Internet". Permission to use the survey data was granted by the Pew Research Center's Internet Project December 2013.
The charts were constructed using rCharts, with plyr, reshape2 packages installed. Simple data preparation steps appear below.
dat2 <- subset(dat,select = c(psraid,icat,rcat,liv,ideocat))
dat1tbl <- table(icat) # Aggregate counts
dat1tblprop <-prop.table(dat1tbl) # Aggregate proportions
tbl1_icat <- as.data.frame(dat1tblprop) #convert to data frame
tbl1_icat$pct=100*round(tbl1_icat$Freq, digits = 3) #Round to one decimal place
tbl1pie <-rename(tbl1_icat,c(icat="label",Freq="prop",pct="value")) # uses plyr
The chart creation code:
pie_icat <- mPlot(x = "label", y = "value", data = tbl1pie, type = "Donut")
pie_icat$print("PieInc", cdn = TRUE, include_assets = TRUE)
Last year, that is in 2009, what was your total family income from all sources, before taxes? Just stop me when I get to the right category...
Which of the following BEST describes the place where you now live?
In general, would you describe your political views as...
A note about the layout. The chart generated by the
mplot call above comes without the percent sign attached to the value in the center of the donut. The layout looks generally like the following. The location and structure of the formatter function is indicated.