Your verification ID is: guDlT7MCuIOFFHSbB3jPFN5QLaQ Big Computing: An example of using ggvis package in R with pipes for data visualization

Thursday, June 4, 2015

An example of using ggvis package in R with pipes for data visualization

This is a example of using the ggvis package with pipes. The ggvis package is a futher development of the ggplot package and designed around the grammar of graphics. This is a very easy to use package the combined with pipes provides asy to read code

First you will need to load install the ggvis package

install.packages("ggvis")

Then you will need to require that package

require(ggvis)
## Loading required package: ggvis

For the first example we are going to uses the build in R data set mtcars. Actually using ggvis without using pipes makes the code look kinda ugly

layer_points(ggvis(mtcars,x = ~wt,y = ~mpg,fill = ~disp,shape = ~factor(cyl)))


As you can see the second code chunk is much easier to read. First is what data set are you using, Second is what are you x and y values and the how points are going to presented (color, shape, etc). Finally it say what kind of graph this is (points, lines, etc). That is basically it.

Just for fun lets do a graph with the iris data set. This is kind fun because unlike the mtcars data set which is really a regression sdata set the iris data set is a classification data set. So we are not looking to see if we can find a trend line but rather how the variable define the groups. In this case that is what species is the iris (setosa, versicolor, virginica). So here is the plot:

iris %>%
  ggvis(x = ~Sepal.Length,y = ~Sepal.Width,fill = ~factor(Species)) %>%
  layer_points()


Pretty cool

2 comments: