My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GadgetExamples  

Featured
Updated Feb 4, 2012 by markus.g...@googlemail.com

googleVis Examples

These examples illustrate how the googleVis package can be used to create interactive charts. More examples are available via demo('googleVis').

Motion Chart

library(googleVis)
Motion=gvisMotionChart(Fruits, idvar="Fruit", timevar="Year", options=list(height=350, width=400))
# Display chart
plot(Motion) 
# Create Google Gadget
cat(createGoogleGadget(Motion), file="motionchart.xml")

Geo Map

Geo=gvisGeoMap(Exports, locationvar="Country", numvar="Profit",
                       options=list(dataMode='regions'))
# Display chart
plot(Geo) 
# Create Google Gadget
cat(createGoogleGadget(Geo), file="geomap.xml")

AndrewGeo <- gvisGeoMap(Andrew, locationvar="LatLong", numvar="Speed_kt", 
      			 hovervar="Category", 
      		         options=list(height=250, width=400, region="US"))

# Display chart
plot(AndrewGeo) 
# Create Google Gadget
cat(createGoogleGadget(AndrewGeo), file="andrewgeomap.xml")

Map

AndrewMap <- gvisMap(Andrew, "LatLong" , "Tip", 
      	      options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE,
		      mapType='terrain', useMapTypeControl=TRUE))
# Display chart
plot(AndrewMap) 
# Create Google Gadget
cat(createGoogleGadget(AndrewMap), file="andrewmap.xml")

Geo Chart

GeoChart <- gvisGeoChart(Exports, "Country", "Profit",
                         options=list(region="150"))
# Display chart
plot(GeoChart)
# Create Google Gadget
cat(createGoogleGadget(GeoChart), file="geochart.xml")

Table

Table <- gvisTable(Exports, options=list(width=400, height=270))
# Display chart
plot(Table) 
# Create Google Gadget
cat(createGoogleGadget(Table), file="table.xml")

PopTable <- gvisTable(Population, options=list(width=600, height=300, page='enable'))
# Display chart
plot(PopTable) 
# Create Google Gadget
cat(createGoogleGadget(PopTable), file="poptable.xml")

Annotated Time Line

AnnoTimeLine  <- gvisAnnotatedTimeLine(Stock, datevar="Date",
                           numvar="Value", idvar="Device",
                           titlevar="Title", annotationvar="Annotation",
                           options=list(displayAnnotations=TRUE,
                             legendPosition='newRow',
                             width=400, height=250)
                           )
# Display chart
plot(AnnoTimeLine) 
# Create Google Gadget
cat(createGoogleGadget(AnnoTimeLine), file="annotimeline.xml")

Tree Map

require(datasets)
states <- data.frame(state.name, state.area)

states3 <- data.frame(state.region, state.division, state.name, state.area)

regions <- aggregate(list(region.area=states3$state.area),
                     list(region=state.region), sum)

divisions <- aggregate(list(division.area=states3$state.area),
                     list(division=state.division, region=state.region),
                     sum)

my.states3 <- data.frame(regionid=c("USA",
                                    as.character(regions$region),
                                    as.character(divisions$division),
                                    as.character(states3$state.name)),
                         parentid=c(NA, rep("USA", 4), 
                                   as.character(divisions$region),
                                   as.character(states3$state.division)),
                         state.area=c(sum(states3$state.area),
                                      regions$region.area,
                                      divisions$division.area,
                                      states3$state.area))

my.states3$state.area.log=log(my.states3$state.area)

statesTree3 <- gvisTreeMap(my.states3, "regionid", "parentid",
                           "state.area", "state.area.log", options=list(showScale=TRUE, width=400, height=300))
# Display chart
plot(statesTree3) 
# Create Google Gadget
cat(createGoogleGadget(statesTree3), file="statestreemap.xml")

Line Chart

df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))
## Line chart
Line <- gvisLineChart(df,
                options=list(legend='none', width=300, height=200))
plot(Line)
cat(createGoogleGadget(Line), file="linechart.xml")

Bar Chart

## Bar chart
Bar <- gvisBarChart(df,
                    options=list(legend='none', width=300, height=200))
plot(Bar)
cat(createGoogleGadget(Bar), file="barchart.xml")

Column Chart

## Column chart
Column <- gvisColumnChart(df,
                          options=list(legend='none', width=300, height=200))
plot(Column)
cat(createGoogleGadget(Column), file="columnchart.xml")

Area Chart

## Area chart
Area <- gvisAreaChart(df,
                          options=list(legend='none', width=300, height=300))
plot(Area)
cat(createGoogleGadget(Area), file="areachart.xml")

Stepped Area Chart

## Stepped Area Chart
SteppedArea <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"),
      options=list(isStacked=TRUE,  width=300, height=290))
plot(SteppedArea)
cat(createGoogleGadget(Area), file="steppedareachart.xml")

Scatter Chart

## Scatter chart
Scatter <- gvisScatterChart(women, options=list(legend="none",
                 lineWidth=2, pointSize=0, hAxis.title="weight",
                 title="Women", vAxis="{title:'height'}",
                 hAxis="{title:'weight'}", width=300, height=300))
plot(Scatter)
cat(createGoogleGadget(Scatter), file="scatterchart.xml")

Bubble Chart

## Bubble chart
Bubble <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses",
                           colorvar="Year", sizevar="Profit",
                           options=list(hAxis='{minValue:75, maxValue:125}',
                             width=500, height=300))

cat(createGoogleGadget(Bubble), file="bubblechart.xml")

Pie Chart

## Pie chart
Pie <- gvisPieChart(CityPopularity,
                    options=list(width=400, height=200))
plot(Pie)
cat(createGoogleGadget(Pie), file="piechart.xml")

Gauge

## Gauge
Gauge <-  gvisGauge(CityPopularity, options=list(min=0, max=800, greenFrom=500,
                                      greenTo=800, yellowFrom=300, yellowTo=500,
                                      redFrom=0, redTo=300, width=300, height=220))
plot(Gauge)
cat(createGoogleGadget(Gauge), file="gauge.xml")

Intensity Map

## Intensity Map
Intensity <- gvisIntensityMap(df)
plot(Intensity)
cat(createGoogleGadget(Intensity), file="intensitymap.xml")

Org Chart

## Org chart
Org <- gvisOrgChart(Regions, options=list(width=600, height=210,
                               size='large', allowCollapse=TRUE))
plot(Org)
cat(createGoogleGadget(Org), file="orgchart.xml")

Candlestick Chart

## Org chart
Candle <- gvisCandlestickChart(OpenClose, xvar="Weekday", low="Low",
                                      open="Open", close="Close",
                                      high="High",
                                      options=list(legend='none',
                                        width=300, height=250))
plot(Candle)
cat(createGoogleGadget(Org), file="candlestickchart.xml")
Comment by sreevath...@gmail.com, Dec 6, 2012

Hello,

Most of the examples are not working.I have successfully installed the required packages and it is giving the error message as "Error in ifelse(interactive()....".Could someone suggest me a solution.

Comment by project member markus.g...@googlemail.com, Dec 6, 2012

Please provide more information, e.g. googleVis version number, R version, OS, etc. see also the R-help guide http://www.r-project.org/posting-guide.html

Comment by Geoffrey...@gmail.com, Feb 3, 2013

Terrific to see a decent "presentation layer" being used with the excellent data-manipulation/statistical functionality of R.

Nothing is more infuriating than the "holier than thou" twats who think that to be 'serious', statistical output has to be of appalling graphical/presentational style. Even back in the 90s (using TSP, for God's sake!) we made SOME effort to do decent charts.

Now if we could just add some 'sphericity' and drop-shadows to the bubble charts, that would be super-awesome... but I bet that functionality already exists and just need to be found and 'tweaked'.

FINALLY, the internet did something good.

Comment by project member markus.g...@googlemail.com, Feb 15, 2013

The example data comes as part of the googleVis package for R.

Comment by jonnie.l...@gmail.com, Aug 31, 2013

For the line chart, I am looking for an option to "check" and "uncheck" lines on a graph. The checked lines would be displayed on the graph, and the unchecked would not. Is there an example with this functionality?

Comment by info.rkm...@gmail.com, Jan 5, 2014

I have found an example to Draw Pie charts clustering on Google Maps http://www.etechpulse.com/2013/07/how-to-create-chart-on-google-maps.html

Thanks


Sign in to add a comment
Powered by Google Project Hosting