SlideShare a Scribd company logo
1 of 55
Introduction to
ggvis visualization
By:- Hemant Singh
Introduction to ggvis
Resources
• R(version 3.5.1)
• R-Studio
• grades data
• cs2m data
• mtcars data
Overview
ggvis is a data visualization package for R which lets you:
• Declaratively describe data graphics with a syntax similar
in spirit to ggplot2.
• Create rich interactive graphics that you can play with
locally in Rstudio or in your browser.
• Leverage shiny’s infrastructure to publish interactive
graphics usable from any browser (either within your
company or to the world).
• The goal is to combine the best of R
• (e.g. every modeling function you can imagine) and the best
of the web (everyone has a web browser). Data manipulation
and transformation are done in R, and the graphics are
rendered in a web browser, using Vega.
• For RStudio users, ggvis graphics display in a viewer panel,
which is possible because RStudio is a web browser.
• ggvis also incorporates shiny’s reactive programming model
and dplyr’s grammar of data transformation.
• The graphics produced by ggvis are fundamentally web
graphics and work very differently from traditional R graphics.
• This allows us to implement exciting new features like
interactivity, but it comes at a cost. For example, every
interactive ggvis plot must be connected to a running R
session (static plots do not need a running R session to be
viewed).
• This is great for exploration, because you can do anything in
your interactive plot you can do in R.
This vignette is divided into four main sections:
• Dive into plotting with ggvis().
• Add interactivity with the mouse and keyboard.
• Create more types of graphic by controlling the layer
type.
• Build up rich graphics with multiple layers.
ggvis()
• Every ggvis graphic starts with a call to ggvis().
• The first argument is the data set that you want to
plot, and the other arguments describe how to map
variables to visual properties.
• Install the ggvis package by using below command.
install.packages(ggvis)
library(ggvis)
p <- ggvis(mtcars, x = ~wt, y = ~mpg)
• This doesn’t actually plot anything because you haven’t
told ggvis how to display your data. You do that by
layering visual elements, for example with layer_points().
• Now,if I’ll add a layer in the above script,
the output like:
Script:
p <- ggvis(mtcars, x = ~wt, y = ~mpg)
layer_points(p)
Or
layer_points(ggvis(mtcars, x = ~wt, y = ~mpg))
To make life easier ggvis uses the
%>% (pronounced pipe) function from the magrittr package.
That allows you to rewrite the previous function call as:
-> mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
layer_points()
• The first two arguments to ggvis() are usually the
position, so by convention you can drop x and y .
• Now, we can write the script like this also.
->mtcars %>% ggvis(~mpg, ~disp) %>%
layer_points()
-> cs2m %>% ggvis( ~Chlstrl, ~AnxtyLH) %>%
layer_points()
• Using the layer_boxplots()
-> grades %>% ggvis(~ethnicity, ~gpa,fill = "blue") %>%
layer_boxplots()
-> cs2m %>% ggvis(x = ~BP , y = ~Age, fill = "blue")
%>% layer_boxplots()
 Let’s move towards more interesting plots, adding more
variables in one plot.
 You can add more variables to the plot by mapping them to
other visual properties like fill, stroke, size and shape in
mtcars dataset.
 Similarly, we can add more variables in other datasets like
cs2m and grades.
->mtcars %>% ggvis(~mpg, ~disp, fill = ~vs) %>%
layer_points()
-> grades %>% ggvis(~percent, ~final, fill = ~grade)
%>% layer_points()
->cs2m %>% ggvis(~Age, ~BP , fill = ~Prgnt) %>%
layer_points()
Adding more variables with their size.
->grades %>% ggvis(~gpa, ~final,size = ethnicity)
%>% layer_points()
->mtcars %>% ggvis(~mpg, ~disp, size = ~vs) %>%
layer_points()
->cs2m %>% ggvis(~Age,~BP, shape = factor(Prgnt))
%>% layer_points()
• Adding more variables according to their size with
different symbols.
->mtcars %>% ggvis(~mpg, ~disp, shape = ~factor(cyl)) %>%
layer_points()
->grades %>% ggvis(~percent,~gpa , shape =
~factor(ethnicity)) %>% layer_points()
Interaction
• As well as mapping visual properties to variables or
setting them to specific values, you can also connect
them to interactive controls.
• The following example allows you to control the size and
opacity of points with two sliders.
• To finish with a plot, press the stop button in Rstudio, or
close the browser window and then press Escape or Ctrl
+ C in R.
->mtcars %>%
ggvis(~wt, ~mpg, size := input_slider(10, 100),
opacity := input_slider(0, 1)) %>% layer_points()
->cs2m %>%
ggvis(~Age,~BP, size := input_slider(10,100),
opacity := input_slider(0,1))%>% layer_points()
->grades %>% ggvis(~percent,~final, size :=
input_slider(10,100),opacity := input_slider(1,0))
%>%layer_points()
We can also connect interactive components to other plot
parameters like the width and centers of histogram bins:
HISTOGRAMS IN ggvis()
->mtcars %>% ggvis(~wt) %>%
layer_histograms(width = input_slider(0, 2, step = 0.10, label =
"width"),
center = input_slider(0, 2, step = 0.05, label = "center"))
->cs2m %>%
ggvis(~Age) %>%
layer_histograms(width = input_slider(0,2,step = 0.10,label
= "width"), center = input_slider(0,2,0.05,label = "center"))
->grades%>%ggvis(~percent) %>%
layer_histograms(width = input_slider(0, 2, step = 0.10,
label = "width"), center = input_slider(0, 2, step = 0.05,
label = "center"))
LAYERS
So far, you seen three layer Functions:
layer_points() ,layer_boxplots() and layer_histograms().
There are many other layers, and they can be roughly
categorised into two types:
Simple, which include primitives like points, lines and rectangles.
Compound, which combine data transformations with one or
more simple layers.
All layer functions use the plural, not the singular. Think the verb,
not the noun: I’m going to layer some points onto my plot.
Simple layers
There are five simple layers:
• layer_points()
• layer_paths()
• layer_ribbons()
• layer_rects()
• layer_text()
layer_points()
->mtcars %>% ggvis(~wt, ~mpg) %>% layer_points()
Try these commands:
->grades %>% ggvis(~percent, ~final, fill = ~grade) %>%
layer_points()
->cs2m %>% ggvis(~Age, ~BP , fill = ~Prgnt) %>%
layer_points()
layer_paths()
->cs2m %>% ggvis(~Age,~BP) %>% layer_paths()
• Try these commands:
->grades %>% ggvis(~quiz1,~total) %>% layer_paths()
->mtcars %>% ggvis(~cyl,~vs) %>% layer_paths()
layer_ribbons()
->grades %>% ggvis(~gpa,~final) %>% layer_ribbons()
layer_rects()
->set.seed(1014)
df <- data.frame(x1 = runif(5), x2 = runif(5), y1 = runif(5), y2
= runif(5))
df %>% ggvis(~x1, ~y1, x2 = ~x2, y2 = ~y2, fillOpacity :=
0.1) %>% layer_rects()
layer_text()
The text layer has many new options to control the
apperance of the text:
• text (the label),
• dx and dy (margin in pixels between text and anchor point),
• angle (rotate the text),
• font (font name),
• fontSize (size in pixels),
• fontWeight (e.g. bold or normal),
• fontStyle (e.g. italic or normal.)
->df <- data.frame(x = 3:1, y = c(1, 3, 2), label = c("a",
"b", "c"))
df %>% ggvis(~x, ~y, text := ~label) %>%
layer_text(fontSize :=50,angle := 45)
Compound layers
The four most common compound layers are:
• layer_lines()
• layer_histograms()
• layer_freqpolys()
• layer_smooths()
layer_lines()
->mtcars %>% ggvis(~cyl, ~drat) %>%
layer_lines()
Try these commands:
->cs2m %>% ggvis(~Age, ~BP) %>% layer_lines()
->grades %>% ggvis(~quiz5,~gpa) %>% layer_lines()
layer_histograms()
->grades %>% ggvis(~final) %>% layer_histograms()
Try these commands:
->mtcars %>% ggvis(~disp) %>% layer_histograms()
->cs2m %>% ggvis(~BP) %>% layer_histograms()
layer_smooths()
->cs2m %>% ggvis(~Age,~Prgnt) %>% layer_smooths()
Try these commands:
->mtcars %>% ggvis(~wt, ~cyl) %>% layer_smooths()
->grades%>% ggvis(~percent,~final) %>%
layer_smooths()
Multiple layers
• Rich graphics can be created by combining multiple
layers on the same plot.
• This easier to do: just layer on multiple elements:
->cs2m %>% ggvis(~Age,~BP) %>%
layer_smooths()%>%
layer_points()
Try these commands:
-> mtcars %>% ggvis(~wt, ~mpg) %>%
layer_smooths() %>%
layer_points()
-> grades %>% ggvis(~final,~ethnicity) %>%
layer_smooths() %>%
layer_points()
-> mtcars %>% ggvis(~wt, ~mpg) %>%
layer_smooths(span = 1) %>%
layer_smooths(span = 0.3, stroke := "red")
ggvis interactivity
• Ggvis interactivity is built on top of Shiny’s reactive programming
model.
• It’s possible to use ggvis without understanding how Shiny works,
but you’ll be limited to relatively simple interactions. The first part
of this vignette describes basic interactive controls, which provide a
quick and easy way to add basic interactivity to a plot.
• They are not very flexible, but they cover the most common
interactive needs and you don’t need to know anything about Shiny
to use them.
We are going to learn how to do:
Basic interactive controls
 Arguments
 Multiple outputs
 Property mappings
 Limitations
Basic interactive controls
A plot with basic interactive controls looks very similar to a static plot. You
just replace constant values with functions that produce interactive controls
like input_slider()

More Related Content

Similar to Introduction to ggvis visualization

[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R台灣資料科學年會
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)Kevin Lee
 
Press the link to see the book from my google drive.https.docx
Press the link to see the book from my google drive.https.docxPress the link to see the book from my google drive.https.docx
Press the link to see the book from my google drive.https.docxChantellPantoja184
 
Maths&programming forartists wip
Maths&programming forartists wipMaths&programming forartists wip
Maths&programming forartists wipkedar nath
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web AppsEPAM
 
R Programming Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfd
R Programming  Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfdR Programming  Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfd
R Programming Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfdvaibhavkandalkar2
 
Introduction to the Stat-JR software package
Introduction to the Stat-JR software packageIntroduction to the Stat-JR software package
Introduction to the Stat-JR software packageUniversity of Southampton
 
An Introduction to NV_path_rendering
An Introduction to NV_path_renderingAn Introduction to NV_path_rendering
An Introduction to NV_path_renderingMark Kilgard
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical ComputingNaveed Rehman
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationAnthony Starks
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLJim Mlodgenski
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Gabriel Moreira
 

Similar to Introduction to ggvis visualization (20)

[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)
 
Press the link to see the book from my google drive.https.docx
Press the link to see the book from my google drive.https.docxPress the link to see the book from my google drive.https.docx
Press the link to see the book from my google drive.https.docx
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
R studio
R studio R studio
R studio
 
Maths&programming forartists wip
Maths&programming forartists wipMaths&programming forartists wip
Maths&programming forartists wip
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web Apps
 
Computation Assignment Help
Computation Assignment Help Computation Assignment Help
Computation Assignment Help
 
R Programming Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfd
R Programming  Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfdR Programming  Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfd
R Programming Magrittrdfgdfsgfdgfdgfdgfdsg fsd gdfsgdf gdf gdfsgfd
 
Introduction to the Stat-JR software package
Introduction to the Stat-JR software packageIntroduction to the Stat-JR software package
Introduction to the Stat-JR software package
 
An Introduction to NV_path_rendering
An Introduction to NV_path_renderingAn Introduction to NV_path_rendering
An Introduction to NV_path_rendering
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generation
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQL
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
R basics
R basicsR basics
R basics
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017
 

Recently uploaded

GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...ThinkInnovation
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 

Recently uploaded (20)

꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 

Introduction to ggvis visualization

  • 3. Resources • R(version 3.5.1) • R-Studio • grades data • cs2m data • mtcars data
  • 4. Overview ggvis is a data visualization package for R which lets you: • Declaratively describe data graphics with a syntax similar in spirit to ggplot2. • Create rich interactive graphics that you can play with locally in Rstudio or in your browser. • Leverage shiny’s infrastructure to publish interactive graphics usable from any browser (either within your company or to the world).
  • 5. • The goal is to combine the best of R • (e.g. every modeling function you can imagine) and the best of the web (everyone has a web browser). Data manipulation and transformation are done in R, and the graphics are rendered in a web browser, using Vega. • For RStudio users, ggvis graphics display in a viewer panel, which is possible because RStudio is a web browser. • ggvis also incorporates shiny’s reactive programming model and dplyr’s grammar of data transformation.
  • 6. • The graphics produced by ggvis are fundamentally web graphics and work very differently from traditional R graphics. • This allows us to implement exciting new features like interactivity, but it comes at a cost. For example, every interactive ggvis plot must be connected to a running R session (static plots do not need a running R session to be viewed). • This is great for exploration, because you can do anything in your interactive plot you can do in R.
  • 7. This vignette is divided into four main sections: • Dive into plotting with ggvis(). • Add interactivity with the mouse and keyboard. • Create more types of graphic by controlling the layer type. • Build up rich graphics with multiple layers.
  • 8. ggvis() • Every ggvis graphic starts with a call to ggvis(). • The first argument is the data set that you want to plot, and the other arguments describe how to map variables to visual properties. • Install the ggvis package by using below command.
  • 9. install.packages(ggvis) library(ggvis) p <- ggvis(mtcars, x = ~wt, y = ~mpg) • This doesn’t actually plot anything because you haven’t told ggvis how to display your data. You do that by layering visual elements, for example with layer_points().
  • 10. • Now,if I’ll add a layer in the above script, the output like: Script: p <- ggvis(mtcars, x = ~wt, y = ~mpg) layer_points(p) Or layer_points(ggvis(mtcars, x = ~wt, y = ~mpg))
  • 11.
  • 12. To make life easier ggvis uses the %>% (pronounced pipe) function from the magrittr package. That allows you to rewrite the previous function call as: -> mtcars %>% ggvis(x = ~wt, y = ~mpg) %>% layer_points()
  • 13. • The first two arguments to ggvis() are usually the position, so by convention you can drop x and y . • Now, we can write the script like this also. ->mtcars %>% ggvis(~mpg, ~disp) %>% layer_points() -> cs2m %>% ggvis( ~Chlstrl, ~AnxtyLH) %>% layer_points()
  • 14. • Using the layer_boxplots() -> grades %>% ggvis(~ethnicity, ~gpa,fill = "blue") %>% layer_boxplots()
  • 15. -> cs2m %>% ggvis(x = ~BP , y = ~Age, fill = "blue") %>% layer_boxplots()
  • 16.  Let’s move towards more interesting plots, adding more variables in one plot.  You can add more variables to the plot by mapping them to other visual properties like fill, stroke, size and shape in mtcars dataset.  Similarly, we can add more variables in other datasets like cs2m and grades.
  • 17. ->mtcars %>% ggvis(~mpg, ~disp, fill = ~vs) %>% layer_points()
  • 18. -> grades %>% ggvis(~percent, ~final, fill = ~grade) %>% layer_points()
  • 19. ->cs2m %>% ggvis(~Age, ~BP , fill = ~Prgnt) %>% layer_points()
  • 20. Adding more variables with their size. ->grades %>% ggvis(~gpa, ~final,size = ethnicity) %>% layer_points()
  • 21. ->mtcars %>% ggvis(~mpg, ~disp, size = ~vs) %>% layer_points()
  • 22. ->cs2m %>% ggvis(~Age,~BP, shape = factor(Prgnt)) %>% layer_points()
  • 23. • Adding more variables according to their size with different symbols. ->mtcars %>% ggvis(~mpg, ~disp, shape = ~factor(cyl)) %>% layer_points()
  • 24. ->grades %>% ggvis(~percent,~gpa , shape = ~factor(ethnicity)) %>% layer_points()
  • 25. Interaction • As well as mapping visual properties to variables or setting them to specific values, you can also connect them to interactive controls. • The following example allows you to control the size and opacity of points with two sliders. • To finish with a plot, press the stop button in Rstudio, or close the browser window and then press Escape or Ctrl + C in R.
  • 26. ->mtcars %>% ggvis(~wt, ~mpg, size := input_slider(10, 100), opacity := input_slider(0, 1)) %>% layer_points()
  • 27. ->cs2m %>% ggvis(~Age,~BP, size := input_slider(10,100), opacity := input_slider(0,1))%>% layer_points()
  • 28. ->grades %>% ggvis(~percent,~final, size := input_slider(10,100),opacity := input_slider(1,0)) %>%layer_points()
  • 29. We can also connect interactive components to other plot parameters like the width and centers of histogram bins: HISTOGRAMS IN ggvis() ->mtcars %>% ggvis(~wt) %>% layer_histograms(width = input_slider(0, 2, step = 0.10, label = "width"), center = input_slider(0, 2, step = 0.05, label = "center"))
  • 30.
  • 31. ->cs2m %>% ggvis(~Age) %>% layer_histograms(width = input_slider(0,2,step = 0.10,label = "width"), center = input_slider(0,2,0.05,label = "center"))
  • 32. ->grades%>%ggvis(~percent) %>% layer_histograms(width = input_slider(0, 2, step = 0.10, label = "width"), center = input_slider(0, 2, step = 0.05, label = "center"))
  • 33. LAYERS So far, you seen three layer Functions: layer_points() ,layer_boxplots() and layer_histograms(). There are many other layers, and they can be roughly categorised into two types: Simple, which include primitives like points, lines and rectangles. Compound, which combine data transformations with one or more simple layers. All layer functions use the plural, not the singular. Think the verb, not the noun: I’m going to layer some points onto my plot.
  • 34. Simple layers There are five simple layers: • layer_points() • layer_paths() • layer_ribbons() • layer_rects() • layer_text()
  • 35. layer_points() ->mtcars %>% ggvis(~wt, ~mpg) %>% layer_points()
  • 36. Try these commands: ->grades %>% ggvis(~percent, ~final, fill = ~grade) %>% layer_points() ->cs2m %>% ggvis(~Age, ~BP , fill = ~Prgnt) %>% layer_points()
  • 38. • Try these commands: ->grades %>% ggvis(~quiz1,~total) %>% layer_paths() ->mtcars %>% ggvis(~cyl,~vs) %>% layer_paths()
  • 40. layer_rects() ->set.seed(1014) df <- data.frame(x1 = runif(5), x2 = runif(5), y1 = runif(5), y2 = runif(5)) df %>% ggvis(~x1, ~y1, x2 = ~x2, y2 = ~y2, fillOpacity := 0.1) %>% layer_rects()
  • 41. layer_text() The text layer has many new options to control the apperance of the text: • text (the label), • dx and dy (margin in pixels between text and anchor point), • angle (rotate the text), • font (font name), • fontSize (size in pixels), • fontWeight (e.g. bold or normal), • fontStyle (e.g. italic or normal.)
  • 42. ->df <- data.frame(x = 3:1, y = c(1, 3, 2), label = c("a", "b", "c")) df %>% ggvis(~x, ~y, text := ~label) %>% layer_text(fontSize :=50,angle := 45)
  • 43. Compound layers The four most common compound layers are: • layer_lines() • layer_histograms() • layer_freqpolys() • layer_smooths()
  • 44. layer_lines() ->mtcars %>% ggvis(~cyl, ~drat) %>% layer_lines()
  • 45. Try these commands: ->cs2m %>% ggvis(~Age, ~BP) %>% layer_lines() ->grades %>% ggvis(~quiz5,~gpa) %>% layer_lines()
  • 47. Try these commands: ->mtcars %>% ggvis(~disp) %>% layer_histograms() ->cs2m %>% ggvis(~BP) %>% layer_histograms()
  • 49. Try these commands: ->mtcars %>% ggvis(~wt, ~cyl) %>% layer_smooths() ->grades%>% ggvis(~percent,~final) %>% layer_smooths()
  • 50. Multiple layers • Rich graphics can be created by combining multiple layers on the same plot. • This easier to do: just layer on multiple elements:
  • 51. ->cs2m %>% ggvis(~Age,~BP) %>% layer_smooths()%>% layer_points()
  • 52. Try these commands: -> mtcars %>% ggvis(~wt, ~mpg) %>% layer_smooths() %>% layer_points() -> grades %>% ggvis(~final,~ethnicity) %>% layer_smooths() %>% layer_points() -> mtcars %>% ggvis(~wt, ~mpg) %>% layer_smooths(span = 1) %>% layer_smooths(span = 0.3, stroke := "red")
  • 53. ggvis interactivity • Ggvis interactivity is built on top of Shiny’s reactive programming model. • It’s possible to use ggvis without understanding how Shiny works, but you’ll be limited to relatively simple interactions. The first part of this vignette describes basic interactive controls, which provide a quick and easy way to add basic interactivity to a plot. • They are not very flexible, but they cover the most common interactive needs and you don’t need to know anything about Shiny to use them.
  • 54. We are going to learn how to do: Basic interactive controls  Arguments  Multiple outputs  Property mappings  Limitations
  • 55. Basic interactive controls A plot with basic interactive controls looks very similar to a static plot. You just replace constant values with functions that produce interactive controls like input_slider()