GeoMap and HTML Table

##Make sure the r chunk code is written as {r, results='asis'}
##Visualization of Canadian population data

suppressPackageStartupMessages(library(googleVis))

##Get the population data
##Data source: http://en.wikipedia.org/wiki/List_of_Canadian_provinces_and_territories_by_population

Code=c("CA-AB","CA-BC","CA-MB","CA-NB","CA-NL","CA-NS","CA-ON","CA-PE","CA-QC","CA-SK","CA-NT","CA-NU","CA-YT")
Province= c("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Nova Scotia","Ontario","Prince Edward","Quebec","Saskachewan","Northwest Terrotories","Nunavut","Yukon")
Population_CA=c(3645257,4400057,1208268,751171,514536,921727,12851821,140204,7903001,1033381,41462,31906,33897)

data_CA= data.frame(Code, Province, Population_CA)
Map=gvisGeoMap(data_CA,locationvar="Code",numvar="Population_CA",hovervar="Province",options=list(region="CA",color="values"))

Table = gvisTable(data_CA[,2:3], formats=list(Population_CA="#,###"))

MapandTable =gvisMerge(Map, Table,horizontal=TRUE,chartid="MapandTable1")
##If you want to just show in a browser without displaying in rpubs
##use instead plot(MapandTable). Otherwise you must use print function.

print(MapandTable,"chart")
##Fifth column in Population data is flag. Remove this column to avoid any problem
PopTable = gvisTable(Population[-5], formats=list(Population="#,###"),options = list(width = 600, height = 300, page ="enable"))
print(PopTable, "chart")
##Create Column & pie Charts

ColChart=gvisColumnChart(data_CA[,2:3],xvar="Province",yvar="Population_CA",chartid="Colchart1",options=list(height=600,width=600))

##Create Pie Charts
pie=gvisPieChart(data_CA[,2:3],options=list(height=600,width=600),chartid="Pie1")
ColandPie =gvisMerge(ColChart, pie,horizontal=TRUE,chartid="ColandPie")
print(ColandPie,"chart")