Transcription of An introduction to rggobi
1 AN introduction TO RGGOBIAn introduction to rggobiHadley Wickham, Michael Lawrence,Duncan Temple Lang, Deborah F SwayneIntroductionThe rggobi package provides a command-line inter-face to GGobi, an interactive and dynamic graph-ics package. rggobi complements GGobi s graphi-cal user interface, providing a way to fluidly transi-tion between analysis and exploration, as well as au-tomating common tasks. It builds on the first versionof rggobi to provide a more robust and user friendlyinterface. In this article, we will show you how youcan starting using rggobi now, and learn some waysto gain insight into your data using a combination ofanalysis and do assume some familiarity with GGobi.
2 Ifyou re not familiar, but would like to learn morehave a look at the GGobi web site, , especially the demos of GGobi s capa-bilities found Youwill also need to have a copy of GGobi installed be-fore continuing: download a version for your plat-form Youcan then install rggobi and it s dependencies (" rggobi ", dep=T).This article introduces the three main compo-nents of rggobi , with examples of how you might usethem in day-to-day tasks: Getting data into and out of GGobi. Modifying observation-level attributes, or au-tomatic brushing. Basic plot will also disucess some advanced techniquessuch as creating animations with GGobi, edges andlongitudinal data. Finally, a case study shows howto use rggobi to create a visualisation for a statisticalalgorithm: data from R into GGobi is easy:g <- ggobi(mtcars).
3 This creates aGGobiobjectcalledg. Getting data out isn t much harder, justindex thatGGobiobject by position,g[[1]], orby name,g[["mtcars"]],g$mtcars. These returnGGobiDataobjects which are linked to the data inGGobi. These act just like regular data frames, exceptthat changes are synchronised with GGobi. You canget a static copy of the data you have your data in GGobi, it s easy to dosomething that was hard before: finding multivariateoutliers. It is customary to look at uni- or bivariateplots to look for uni- or bivariate outliers, but higherdimensional outliers may go unnoticed. Looking forthese outliers is easy to do with the tour. Open yourdata with GGobi and then change to the tour viewand select all the variables.
4 Watch the tour and lookfor points that are far away or move differently fromthe others these are more data sets to an open GGobi is alsoeasy:g$mtcars2 <- mtcarswill add another dataset named mtcars2 . You can load any file typethat GGobi recognises by passing the path to that conjunction withggobi_find_file, which locatesfiles in the GGobi installation directory, this makes iteasy to load GGobi sample data. This example loadsthe olives data set included with (ggobi_find_file("data", " "))Modifying observation-levelattributes, or automatic brushingBrushing lets you interactively change the colour,glyph type and size of points. Brushing is linked,which means that these changes will propagate toevery plot in which the brushed observations are dis-played.
5 Brushing includes shadowing, where pointssit in the background and have less visual impact,and exclusion, where points are completed excludedfrom the plot. You can brush points automatically ,from R, using the following functions to: change glyph colour withglyph_colour change glyph size withglyph_size change glyph type withglyph_type shadow and unshadow points withshadowed exclude and include points withexcludedEach of these get or set the current values forthe specifiedGGobiData. The getters are useful forretrieving information that you have created whilebrushing in GGobi, and the setters can be used tochange the appearance of points based on model in-formation, or to create animations.
6 They can also beused to store, and then later recreate, the results of acomplicated sequence of brushing example demonstrates the use of theglyph_colourto show the results of clustering theinfamous Iris data using hierachical clustering. Us-ing GGobi allows us to investigate the clustering inthe original dimensions of the data. The graphicshows a single projection from the grand introduction TO RGGOBIg <- ggobi(iris)clustering <- hclust(dist(iris[,1:4]),method="average" )glyph_colour(g[1]) <- cuttree(clustering, 3)Another function,selected, returns a logical vec-tor indicating if each point is currently under thebrush. This could be used to further explore inter-esting or unusual a window containingone or more related plots.
7 With rggobi you can cre-ate new displays, change the interaction or projectionmode of an existing plot, or change which variablesare retrieve a list of displays, use thedisplaysfunction. To create a new display use thedisplaymethod on aGGobiDataobject. You ll need to specifythe type of plot you want (the default is a XY Plot)and which variables to include. For example:g <- ggobi(mtcars)display(g[1], vars=list(X=4, Y=5))display(g[1], vars=list(X="drat", Y="hp"))display(g[1], "Parallel Coordinates Display")display(g[1], "2D Tour")The following types of displays are available inGGobi:NameVariables1D Plot1 XXY Plot1 X, 1 Y1D TournXRotation1 X, 1 Y, 1 Z2D TournX2x1D TournX,nYScatterplot MatrixnXParallel Coordinates DisplaynXTime Series1 X,nYBarchart1 XAfter creating a plot you can get and set the dis-played variables using thevariableandvariable<-methods.
8 Because of the range of plot types inGGobi, variables should be specified as a list contain-ingX,YandZcharacter vectors listing the variable orvariables to be used for each <- ggobi(mtcars)d <- display(g[1],"Parallel Coordinates Display")variables(d)variables(d) <- list(X=8:6)variables(d) <- list(X=8:1)variables(d)Another useful function isggobi_display_save_picture,which saves the contents of a GGobi display to afile on disk. This is what we used to create the im-ages in this document. This creates an exact (raster)copy of the GGobi display. If you want to createpublication quality graphics from GGobi, have alook at theDescribeDisplayplugin and package Thesecreate R versions of your GGobi changes that you make to theGGobiDataobjectsare updated in GGobi immediately, so you can eas-ily create animations.
9 This example scrolls through along time series:df <- (x=1:2000,y=sin(1:2000 * pi/20) + runif(2000, max= ))g <- ggobi_longitudinal(df[1:100, ])df_g <- g[1]for(i in 1:1901) {df_g[, 2] <- df[i:(i + 99), 2]}Edge dataEdge data sets are a special type of dataset. Insteadof representing points, they represent connections, oredges, between observations. These can be used torepresent many different types of data, for example,distances between observations, social relationships,biological pathways, and so STUDYAN introduction TO RGGOBIIn this example we are going to visualise somedata from the social network analysis package: mar-ital and business relationships between Florentinefamilies in the 15th (graph)library(SNAData)data(business, marital, florentineAttrs)g <- ggobi(florentineAttrs)edges(g) <- businessedges(g) <- maritalThis example creates two edge datasets.
10 We canuse the edges menu in GGobi to change between thedifferent edge is this stored in GGobi? An edge datasetrecords the names of the source and destination ob-servations for each edge. You can convert a regulardataset into a edge dataset with takes a matrix with two columns, source anddestination names, with a row for each edge obser-vation. Typically, you will need to add a new dataframe with number of rows equal to the number ofedges you want to addLongitudinal dataA special case of data with edges is time series orlongitudinal data, in which observations adjacent intime are connected with a line. rggobi provides aconvenient function for creating edge sets for longi-tudinal data,ggobi_longitudinal.