Testing some nice graphs from Google Visualization API through R googleVis package and PluginR in Tiki.
googleVIs R-package graphs through PluginR in Tiki
Section 1 - Testing the Installation
This code:
Copy to clipboard
{RR(loadandsave="1", wikisyntax="0")}
# Example adapted from the ones shown here: http://code.google.com/p/google-motion-charts-with-r/
# and here: http://www.r-bloggers.com/interactive-reports-in-r-with-knitr-and-rstudio/
#
# If required the first time, uncomment the following line/s to install the required R packages, and edit the path and url to suite your needs.
if(!require(googleVis)){
install.packages("googleVis", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/")
}
{RR}
Produces (nothing if the package is already installed):
Section 2 - Scatter Chart
R Code
df <- data.frame(x = 1:10, y = 1:10)
## load the googleVis package
suppressPackageStartupMessages(library(googleVis))
## create the scatter chart
sc <- gvisScatterChart(data=df,
options=list(width=300, height=300,
legend='none',
hAxis="{title:'x'}",
vAxis="{title:'y'}")
)
print(sc, "chart") ## same as cat(sc$html$chart)
Section 3 - GeoChart USA
R Code
require(googleVis)
geo <- gvisGeoChart(CityPopularity, locationvar = "City",
colorvar = "Popularity",
options = list(region="US", height=350, displayMode = "markers",
colorAxis = "{colors: ['orange','blue']}") )
print(geo, "chart")
Section 4 - Motion Chart (impressive!)
R Code
require(googleVis)
M <- gvisMotionChart(Fruits, "Fruit", "Year", options = list(width = 550,
height = 450))
print(M, "chart")
Once everything is ready in your system (all packages installed, etc), you'll see something like this:
Section 5 - Spain by Autonomous Regions
R Code
require(googleVis)
####################################################
# Por Autonomias
####################################################
RegionPopular<-data.frame(
Region=c('ES-IB', 'ES-CT', 'ES-EX', 'ES-TO')
,Popular=c(100,200,300, 250)
)
G3 <- gvisGeoMap(RegionPopular, locationvar='Region', numvar='Popular',
options=list(region="ES", dataMode="regions",
width=600, height=400))
#plot(G3)
print(G3, "chart")
Section 6 - Spain by provinces
R Code
require(googleVis)
####################################################
# Por Provincias
####################################################
RegionPopular<-data.frame(
Region=c('ES-PO', 'ES-SA', 'ES-VA', 'ES-TO')
,Popular=c(400,200,300, 250)
)
G4 <- gvisGeoMap(RegionPopular, locationvar='Region', numvar='Popular',
options=list(region="ES", dataMode="markers",
width=600, height=400))
#plot(G4)
print(G4, "chart")
Section 7 - Spain by cities
R Code
require(googleVis)
###################################################
# Por Ciudades
###################################################
CiudadPopular<-data.frame(
Ciudad=c('Madrid', 'Barcelona', 'Albacete')
,Popular=c(100,200,300)
)
G5 <- gvisGeoMap(CiudadPopular, locationvar='Ciudad', numvar='Popular',
options=list(region='ES', height=350,
dataMode='markers',
colors='[0xFF8747, 0xFFB581, 0xc06000]'))
# plot(G5)
print(G5, "chart")