Showing posts with label gvisGeoChart. Show all posts
Showing posts with label gvisGeoChart. Show all posts

googleVis 0.4.7 with RStudio integration on CRAN

In my previous post, I presented a preview version of googleVis that provided an integration with RStudio's Viewer pane (introduced with version 0.98.441).

Over 80% in my little survey favoured the new default output mechanism of googleVis within RStudio. Hence, I uploaded googleVis 0.4.7 on CRAN over the weekend.

However, there were also some thoughtful comments, which suggested that the RStudio Viewer pane is not always the best option. Indeed, Flash charts and gvisMerge output will still be displayed in your default browser, but also if you work on larger charts and with smaller screen, then the browser might still be the better option compared to the Viewer pane - of course you can launch the browser from the Viewer pane as well.

Hence, googleVis gained a new option 'googleVis.viewer' that controls the default output of the googleVis plot method. On package load it is set to getOption("viewer") and if you use RStudio, then its viewer pane will be used for displaying non-Flash and un-merged charts. You can set options("googleVis.viewer" = NULL) and the googleVis plot function will open all output in the default browser again. Thanks to J.J. from RStudio for the tip.

The screen shot below shows a geo chart within the RStudio Viewer pane of the
devastating typhoon track of Haiyan that hit Southeast Asia last week.



Session Info

RStudio v0.98.456 and R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] googleVis_0.4.7 XML_3.95-0.2   

loaded via a namespace (and not attached):
[1] RJSONIO_1.0-3 tools_3.0.2  

googleVis 0.4.3 released with improved Geocharts

The Google Charts Tools provide two kinds of heat map charts for geographical data, the Flash based Geomap and the HTML5/SVG based Geochart.

I prefer the Geochart as it doesn't require Flash, but so far there have been two shortcomings with it: I couldn't add additional tooltip information and the default Mercator projection shows Greenland the size of Africa. Both of those issues seemed to have been resolved by Google. Although the features aren't officially documented and released yet, Mitchell Foley from the Google Chart Tools team presented the new developments at the Google I/O 2013 conference in May already.



With version 0.4.3 of googleVis, and thanks to John Muschelli, gvisGeoChart gained a new argument hovervar allowing users to add further information to the tooltip. Additionally, following the examples in Mitchell's presentation I can change the projection as well. The official release from Google shouldn't be too far away.

So, here are again the heat maps of countries' credit ratings from three American and one Chinese rating agency, sourced from Wikipedia. However, this time I use gvisGeoChart, setting the projection to Kavrayskiy VII and the tooltip to the actual rating letter(s), see the R code below.

First steps of using googleVis on shiny

The guys at RStudio have done a fantastic job with shiny. It is really easy to build web apps with R using shiny. With the help of Joe Cheng from RStudio we figured out a way to make googleVis work on shiny as well. This allows you to make use of the Google Charts Tools in your shiny app directly from R. What I present here are three initial examples which seem to work in most browsers. The third example even uses a neat trick to create an animated geo chart.



However, before we upload the next version of googleVis to CRAN we decided to present a preview of version 0.4.0 here, asking for feedback. It would not be fair on the guys behind CRAN to release something into the wild, only to be told by users within a few days that we missed something. Hence, you can get the new version of googleVis only from the download page of our project site for the time being.

You may have read the post on RStudio's blog that the shiny API changed slightly: the reactivePlot and reactiveText functions have been renamed to renderPlot and renderText with simplified input parameters. Thanks to Joe, there is now also a renderGvis function as part of the googleVis package, which works in very much the same way as the other two.

To run the following examples you need shiny version 0.4.0 and googleVis version 0.4.0 or higher.

Changes in life expectancy animated with geo charts

The data of the World Bank is absolutely amazing. I had said this before, but their updated iPhone App gives me a reason to return to this topic. Version 3 of the DataFinder App allows you to visualise the data on your phone, including motion maps, see the screen shot below.

Screen shot of DataFinder 3.0

I was intrigued by the by the changes in life expectancy over time around the world. The average life expectancy of a new born baby in 1960 was only 52.6 years, and don't forget we are in 2012, 52 years later. Babies born in 2009 can expect to live to the age 69.4 years, an increase by nearly 17 years or 32%. That is remarkable. But these are average figures and vary a lot by country.

The world bank's online version of the map unfortunately lacks the the animation of the smartphone app. Thus I was keen to find out if I could reproduce something similar in R based on code and ideas provided to me by Manoj Ananthapadmanabhan and Anand Ramalingam last year. Those ideas had helped me to create the animated geo maps demo "AnimatedGeoMap" of the googleVis R package.

googleVis 0.2.15 is released: Improved geo and bubble charts

The guys behind the Google Visualisation API don't seem to rest. On 22 February 2012 they released an update of their API. Google added options for a gradient colour axis to bubble chart and a magnifying glass to geo chart, which opens when the user hovers over cluttered markers (excluding IE<=8). Those updates have been incorporated into version 0.2.15 of the googleVis package for R.

Examples of new features

Here are two examples demonstrating the new features.

Bubble chart with gradient colour mode

Example of a bubble chart with a colour gradient axis.

googleVis 0.2.13: new stepped area chart and improved geo charts

On 7th December Google published a new version of their Visualisation API. The new version adds a new chart type: Stepped Area Chart and provides improvements to Geo Chart. Now Geo Chart has similar functionality to Geo Map, but while Geo Map requires Flash, Geo Chart doesn't, as it renders SVG/VML graphics. So it also works on your iOS devices.

These new features have been added to the googleVis R package in version 0.2.13, which went live on CRAN a few days ago.

The function gvisSteppedAreaChart works very much in the same way as gvisAreaChart. Here is a little example:

library(googleVis)
df <- data.frame(country=c("US", "GB", "BR"), 
                 val1=c(1,3,4), val2=c(23,12,32))
SteppedArea <- gvisSteppedAreaChart(df, xvar="country", 
                                        yvar=c("val1", "val2"),
                           options=list(isStacked=TRUE, 
                                        width=400, height=150))
plot(SteppedArea2)

The interface to gvisGeoChart changed slightly to take into account the new version of Geo Chart by Google. The argument numvar has been renamed to colorvar and a new argument sizevar has been added. This allows you to set the size and colour of the bubbles in displayMode='markers' depending on columns in your data frame. Further, you can set far more options than you could before, in particular you can set not only the region, but also the resolution of your map. Although more granular maps are not available for all countries, for more details see the Google documentation.

Here are two examples, plotting the test data CityPopularity with a Geo Chart. The first plot shows the popularity of New York, Boston, Miami, Chicago, Los Angeles and Houston on the US map, with the resolution set to 'metros' and region set to 'US'. The Google Map API makes the correct assumption about which cities we mean.

library(googleVis> ## requires googleVis version >= 0.2.13
gcus <- gvisGeoChart(CityPopularity, 
        locationvar="City", colorvar="Popularity", 
          options=list(displayMode="markers", 
                       region="US", resolution="metros"), 
         chartid="GeoChart_US")
plot(gcus)

In the second example we set the region to 'US-TX', therefore Google will look for cities with the same names in Texas. And what a surprise, there are cities/towns named Chicago, Los Angeles, Miami, Boston and of course Houston in Texas.

gctx <- gvisGeoChart(CityPopularity, 
        locationvar="City", colorvar="Popularity", 
          options=list(displayMode="markers", 
                       region="US-TX", resolution="metros"), 
         chartid="GeoChart_TX")
plot(gctx)

With the new version of the Visualisation API Google introduced also the concept of DataTable Roles. This is an interesting idea, as it allows you to add context to the data, similar to the approach used with annotated time lines. Google classifies the DataTable Roles still experimental, but it is a space to watch and ideas on how this could be translated into R will be much appreciated.

And now the news of the googleVis package since version 0.2.10:

Version 0.2.13 [2011-12-19]
==========================

Changes

    o The list of arguments for gvisGeoChart changed:
      - the argument 'numvar' has been renamed to 'colorvar' to
        reflect the updated Google API. Additionally gvisGeoChart
     gained a new argument 'sizevar'.
    o Updated googleVis vignette with a section on using googleVis 
      output in presentations  
    o Renamed demo EventListner to EventListener

NEW FEATURES

    o Google published a new version of their Visualisation API on 7
      December 2011. Some of the new features have been implemented
      into googleVis already:
      - New stepped area chart function gvisSteppedAreaChart
      - gvisGeoChart has a new marker mode, similar to the mode in
       gvisGeoMap. See example(gvisGeoChart) for the new
        functionalities.

Version 0.2.12 [2011-12-07]
==========================

Bug Fixes

    o gvisMotionChart didn't display data with special characters,
      e.g. spaces, &, %, in column names correctly. 
      Thanks to Alexander Holcroft for reporting this issue.

Version 0.2.11 [2011-11-16]
==========================

Changes

   o Updated vignette and documentation with instructions on changing
     the Flash security settings to display Flash charts locally. 
     Thanks to Tony Breyal.
   o New example to plot weekly data with gvisMotionChart
   o Removed local copies of gadget files to reduce package file
     size. A local copy of the R script to generate the original gadget
     files is still included in inst/gadgets 

Version 0.2.10 [2011-09-24]
==========================

Changes

   o Updated section 'Using googleVis output with Google Sites,
     Blogger, etc.' vignette

   o Updated example for gvisMotionChart, showing how the initial
     chart setting can be changed, e.g to display a line chart.

   o New example for gvisAnnotatedTimeLine, showing how to shade
     areas. Thanks to Mike Silberbauer for providing the initial code.    
   
NEW FEATURES
 
    o New demo WorldBank. It demonstrates how country level data can
      be accessed from the World Bank via their API and displayed with a
      Motion Chart. Inspired by Google's Public Data Explorer, see
      http://www.google.com/publicdata/home