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)))
To make the code more readable it is strongly suggested you use pipes when writting code for ggvis. Pipes uses the symbol %>% to link everthing together. Here is what the exact same code looks like using pipes:
mtcars %>%
ggvis(x = ~wt,y = ~mpg, fill = ~disp, shape = ~factor(cyl)) %>%
layer_points()
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
I prefer the old term bloodletter over phlebotomist
ReplyDeletegclub
gclub casino online
จีคลับ
Fighting insects in Khamis Mushait**Combating cockroaches with magic dough in Riyadh**Steam cleaning company in Khamis Mushait**Insulation of bathrooms and kitchens**Moving furniture in Khamis Mushait**Detection of water leaks in Khamis Mushait**Furniture transfer in Riyadh 300 riyals**Repair and maintenance of houses in Riyadh
ReplyDelete