Loading...
 
Skip to main content
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
11
 
1
df <- data.frame(x = 1:10, y = 1:10)
2
## load the googleVis package
3
suppressPackageStartupMessages(library(googleVis))
4
## create the scatter chart
5
sc <- gvisScatterChart(data=df,
6
                        options=list(width=300, height=300,
7
                                     legend='none',
8
                                     hAxis="{title:'x'}",
9
                                     vAxis="{title:'y'}")
10
          )
11
print(sc, "chart")  ## same as cat(sc$html$chart)


Section 3 - GeoChart USA

R Code
6
 
1
require(googleVis)
2
geo <- gvisGeoChart(CityPopularity, locationvar = "City",
3
                    colorvar = "Popularity",
4
          options = list(region="US", height=350, displayMode = "markers",
5
                         colorAxis = "{colors: ['orange','blue']}") )
6
print(geo, "chart")


Section 4 - Motion Chart (impressive!)

R Code
4
 
1
require(googleVis)
2
M <- gvisMotionChart(Fruits, "Fruit", "Year", options = list(width = 550,
3
    height = 450))
4
print(M, "chart")



Once everything is ready in your system (all packages installed, etc), you'll see something like this:

Image


Section 5 - Spain by Autonomous Regions

R Code
14
 
1
require(googleVis)
2
####################################################
3
# Por Autonomias
4
####################################################
5
RegionPopular<-data.frame(
6
  Region=c('ES-IB', 'ES-CT', 'ES-EX', 'ES-TO')
7
  ,Popular=c(100,200,300, 250)
8
)
9
10
G3 <- gvisGeoMap(RegionPopular, locationvar='Region', numvar='Popular',
11
                 options=list(region="ES", dataMode="regions",
12
                              width=600, height=400))
13
#plot(G3)
14
print(G3, "chart")


Section 6 - Spain by provinces


R Code
xxxxxxxxxx
14
 
1
require(googleVis)
2
####################################################
3
# Por Provincias
4
####################################################
5
RegionPopular<-data.frame(
6
  Region=c('ES-PO', 'ES-SA', 'ES-VA', 'ES-TO')
7
  ,Popular=c(400,200,300, 250)
8
)
9
10
G4 <- gvisGeoMap(RegionPopular, locationvar='Region', numvar='Popular',
11
                 options=list(region="ES", dataMode="markers",
12
                              width=600, height=400))
13
#plot(G4)
14
print(G4, "chart")


Section 7 - Spain by cities

R Code
xxxxxxxxxx
16
 
1
require(googleVis)
2
###################################################
3
# Por Ciudades
4
###################################################
5
CiudadPopular<-data.frame(
6
  Ciudad=c('Madrid', 'Barcelona', 'Albacete')
7
  ,Popular=c(100,200,300)
8
)
9
10
G5 <- gvisGeoMap(CiudadPopular, locationvar='Ciudad', numvar='Popular',
11
                 options=list(region='ES', height=350,
12
                              dataMode='markers',
13
                              colors='[0xFF8747, 0xFFB581, 0xc06000]'))
14
15
# plot(G5)
16
print(G5, "chart")


Show PHP error messages