SlideShare a Scribd company logo
1 of 36
Download to read offline
Plotting systems in R
Ilya Zhbannikov
Graphics Devices in R
• Screen device
• File device (pdf, png, jpeg, etc.)
Graphics device: a place to make plot appear
How does a plot get created?
• Call a plotting function, i.e. plot(), xyplot(),
qplot()
• The plot appears on a screen device
• Annotate plot, if necessary
• Save it to file, for example.
Screen and file devices
• How the plot will be used?
• Use screen device for quick visualisation or
exploratory studies.
• Plotting functions (plot(), qplot(), xyplot()) send
output to the screen device by default.
• If the plot will be printed, use file device instead.
Example
attach(mtcars)
head(mtcars[, c("hp", "mpg")])
plot(hp, mpg)
Example
attach(mtcars)
head(mtcars[, c("hp", "mpg")])
plot(hp, mpg)
title("MPG vs. hp”) # Add a title
Available plotting systems
• Base
• lattice
• ggplot2
Base plotting system
• Installed by default
• Quickest way to visualise your data
• Plot can be further updated using additional
options
Simple example
attach(mtcars)
plot(hp, mpg)
Extended example
plot(disp,mpg,
main = "MPG vs. HP", # Add a title
type = "p",
col = "grey", # Change the color of the points
pch = 16, # Change the plotting symbol see help(points)
cex = 1, # Change size of plotting symbol
xlab = “Horse power", # Add a label on the x-axis
ylab = "Miles per Gallon", # Add a label on the y-axis
bty = "n", # Remove the box around the plot
#asp = 1, # Change the y/x aspect ratio see help(plot)
font.axis = 1, # Change axis font to bold italic
col.axis = "black", # Set the color of the axis
xlim = c(20,500), # Set limits on x axis
ylim = c(5,50), # Set limits on y axis
las=1) # Make axis labels parallel to x-axis
Extended example
More examples
More examples
par(mfrow=c(2,2))
• Multivariate data
• Uses formulas
• Single function call
The Lattice Plotting System
The Lattice Plotting System
• lattice: code for producing Trellis graphics,
includes functions like xyplot(), bwplot(), levelplot()
• Grid: implements a different graphics system and
the lattice package are on top of it
Main plot functions
• xyplot(): scatterplots
• bwplot(): boxplots
• histogram(): histograms
• stripplot(): a boxplot points
• dotplot(): plot dots on "violin strings"
• splom(): scatterplot matrix
• levelplot(), contourplot(): for "image" data
Example
library(lattice)
attach(mtcars)
xyplot(mpg ~ hp, data = mtcars)
Extended example
More examples
• See lattice_example_1.R
ggplot2 Plotting System
• “Grammar of Graphics” by Leland Wilkinson,
written by Hadley Wickham
• Data must be a data frame
• Uses grammar
• Web site: http://ggplot2.org
What is "Grammar of Graphics"?
"In brief, the grammar tells us that a statistical
graphic is a mapping from data to aesthetic
attributes (colour, shape, size) of geometric
objects (points, lines, bars). The plot may also
contain statistical transformations of the data and
is drawn on a specific coordinate system”-
ggplot2 book
qplot() and ggplot()
• qplot() - works like plot() function in base
plotting system data
• should represent a data frame
• aesthetic (size, colour, shape) and geoms
(points, lines)
• core of ggplot()
qplot
• qplot() - works like plot() function in base
plotting system data
• Should represent a data frame
• aesthetic (size, colour) and geoms (points,
lines)
• Core of ggplot()
Example
library(ggplot2)
attach(mtcars)
head(mtcars)
# Simple plot:
qplot(data=mtcars,x=hp, y=mpg,main="MPG vs. hp")
Example
# Color gradient
qplot(data=mtcars,x=log(hp),y=log(mpg),color=mpg)
Example
# Boxplots:
qplot(data=mtcars,x=factor(cyl), y=mpg,geom="boxplot", main="MPG vs. # of Cylinders")
Components of ggplot()
• A data frame
• aesthetic mapping (how data are mapped
to colour and size)
• geoms (points, shapes, lines)
• facets
• stats (binning, smoothing, quantiles)
• scales (for aesthetic mapping, i.e.
male=‘red’, female=‘blue’)
• coordinate system
Peng at al, Explanatory Data Analysis, Coursera online class
Steps to plot with ggplot()
• Plots are build up in layers
• Plot the data
• Overlay a summary
• Add metadata and annotation
Peng at al, Explanatory Data Analysis, Coursera online class
Peng at al, Explanatory Data Analysis, Coursera online class
Peng at al, Explanatory Data Analysis, Coursera online class
Example
# Basic:
ggplot(mtcars, aes(hp, mpg)) + geom_point()
Peng at al, Explanatory Data Analysis, Coursera online class
Example
# With color:
ggplot(mtcars, aes(hp, mpg)) + geom_point(aes(color = cyl))
Peng at al, Explanatory Data Analysis, Coursera online class
Example
# Boxplots:
ggplot(data=mtcars, aes(hp, mpg)) + geom_boxplot(aes(as.factor(cyl)))
Peng at al, Explanatory Data Analysis, Coursera online class
Example
# Faceting
mtcars$cyl <- factor(mtcars$cyl)
ggplot(data=mtcars, aes(hp, mpg)) + geom_point() + facet_grid(~ cyl)
Peng at al, Explanatory Data Analysis, Coursera online class
Example
# Faceting
mtcars$cyl <- factor(mtcars$cyl)
ggplot(data=mtcars, aes(hp, mpg)) + geom_point() + facet_grid(~ cyl)
Peng at al, Explanatory Data Analysis, Coursera online class
Example
ggplot(data=mtcars, aes(hp, mpg)) + geom_point() + facet_grid(~ cyl) +
geom_smooth(colour = "blue", size = 1, method=lm)
Resources
• http://www.r-bloggers.com
• http://revolutionanalytics.com
• http://www.statmethods.net (Quick-R)
• Coursera (Data Science Specialisation)

More Related Content

What's hot

Matlab plotting
Matlab plottingMatlab plotting
Matlab plottingpink1710
 
Geo Spatial Plot using R
Geo Spatial Plot using R Geo Spatial Plot using R
Geo Spatial Plot using R Rupak Roy
 
R-ggplot2 package Examples
R-ggplot2 package ExamplesR-ggplot2 package Examples
R-ggplot2 package ExamplesDr. Volkan OBAN
 
peRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysispeRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysisVyacheslav Arbuzov
 
Data visualization using the grammar of graphics
Data visualization using the grammar of graphicsData visualization using the grammar of graphics
Data visualization using the grammar of graphicsRupak Roy
 
DSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser Bootsma
DSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser BootsmaDSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser Bootsma
DSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser BootsmaDeltares
 
ePOM - Intro to Ocean Data Science - Data Visualization
ePOM - Intro to Ocean Data Science - Data VisualizationePOM - Intro to Ocean Data Science - Data Visualization
ePOM - Intro to Ocean Data Science - Data VisualizationGiuseppe Masetti
 
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...Lviv Startup Club
 
Your first TensorFlow programming with Jupyter
Your first TensorFlow programming with JupyterYour first TensorFlow programming with Jupyter
Your first TensorFlow programming with JupyterEtsuji Nakai
 
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...Heroku
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in HeavenR and Visualization: A match made in Heaven
R and Visualization: A match made in HeavenEdureka!
 
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...Matrunich Consulting
 
ePOM - Intro to Ocean Data Science - Scientific Computing
ePOM - Intro to Ocean Data Science - Scientific ComputingePOM - Intro to Ocean Data Science - Scientific Computing
ePOM - Intro to Ocean Data Science - Scientific ComputingGiuseppe Masetti
 
Machine Learning Basics for Web Application Developers
Machine Learning Basics for Web Application DevelopersMachine Learning Basics for Web Application Developers
Machine Learning Basics for Web Application DevelopersEtsuji Nakai
 

What's hot (19)

Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Geo Spatial Plot using R
Geo Spatial Plot using R Geo Spatial Plot using R
Geo Spatial Plot using R
 
R-ggplot2 package Examples
R-ggplot2 package ExamplesR-ggplot2 package Examples
R-ggplot2 package Examples
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
 
peRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysispeRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysis
 
Data visualization using the grammar of graphics
Data visualization using the grammar of graphicsData visualization using the grammar of graphics
Data visualization using the grammar of graphics
 
DSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser Bootsma
DSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser BootsmaDSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser Bootsma
DSD-INT 2018 Work with iMOD MODFLOW models in Python - Visser Bootsma
 
ePOM - Intro to Ocean Data Science - Data Visualization
ePOM - Intro to Ocean Data Science - Data VisualizationePOM - Intro to Ocean Data Science - Data Visualization
ePOM - Intro to Ocean Data Science - Data Visualization
 
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
 
Your first TensorFlow programming with Jupyter
Your first TensorFlow programming with JupyterYour first TensorFlow programming with Jupyter
Your first TensorFlow programming with Jupyter
 
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in HeavenR and Visualization: A match made in Heaven
R and Visualization: A match made in Heaven
 
R
RR
R
 
Day 3 plotting.pptx
Day 3   plotting.pptxDay 3   plotting.pptx
Day 3 plotting.pptx
 
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
 
ePOM - Intro to Ocean Data Science - Scientific Computing
ePOM - Intro to Ocean Data Science - Scientific ComputingePOM - Intro to Ocean Data Science - Scientific Computing
ePOM - Intro to Ocean Data Science - Scientific Computing
 
Machine Learning Basics for Web Application Developers
Machine Learning Basics for Web Application DevelopersMachine Learning Basics for Web Application Developers
Machine Learning Basics for Web Application Developers
 
Maps
MapsMaps
Maps
 

Similar to Presentation: Plotting Systems in R

Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using rTahera Shaikh
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
UNit-III. part 2.pdf
UNit-III. part 2.pdfUNit-III. part 2.pdf
UNit-III. part 2.pdfMastiCreation
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlibPiyush rai
 
Lecture 02 visualization and programming
Lecture 02   visualization and programmingLecture 02   visualization and programming
Lecture 02 visualization and programmingSmee Kaem Chann
 
Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2yannabraham
 
Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plottingNimrita Koul
 
Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plottingNimrita Koul
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxSharmilaMore5
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxUNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxBhagyasriPatel2
 
Exploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience SpecialisationExploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience SpecialisationWesley Goi
 

Similar to Presentation: Plotting Systems in R (20)

R training5
R training5R training5
R training5
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using r
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
UNit-III. part 2.pdf
UNit-III. part 2.pdfUNit-III. part 2.pdf
UNit-III. part 2.pdf
 
Lec2
Lec2Lec2
Lec2
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Lecture 02 visualization and programming
Lecture 02   visualization and programmingLecture 02   visualization and programming
Lecture 02 visualization and programming
 
Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2
 
Data Exploration in R.pptx
Data Exploration in R.pptxData Exploration in R.pptx
Data Exploration in R.pptx
 
K10947 Vikas ct
K10947 Vikas ctK10947 Vikas ct
K10947 Vikas ct
 
Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plotting
 
Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plotting
 
Intro matlab
Intro matlabIntro matlab
Intro matlab
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
 
12-IP.pdf
12-IP.pdf12-IP.pdf
12-IP.pdf
 
Python grass
Python grassPython grass
Python grass
 
Time Series.pptx
Time Series.pptxTime Series.pptx
Time Series.pptx
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxUNIT_4_data visualization.pptx
UNIT_4_data visualization.pptx
 
Exploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience SpecialisationExploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience Specialisation
 

Recently uploaded

专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
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
 
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
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
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
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degreeyuu sss
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
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
 

Recently uploaded (20)

专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
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...
 
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🔝
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
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
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
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)
 

Presentation: Plotting Systems in R

  • 1. Plotting systems in R Ilya Zhbannikov
  • 2. Graphics Devices in R • Screen device • File device (pdf, png, jpeg, etc.) Graphics device: a place to make plot appear
  • 3. How does a plot get created? • Call a plotting function, i.e. plot(), xyplot(), qplot() • The plot appears on a screen device • Annotate plot, if necessary • Save it to file, for example.
  • 4. Screen and file devices • How the plot will be used? • Use screen device for quick visualisation or exploratory studies. • Plotting functions (plot(), qplot(), xyplot()) send output to the screen device by default. • If the plot will be printed, use file device instead.
  • 6. Example attach(mtcars) head(mtcars[, c("hp", "mpg")]) plot(hp, mpg) title("MPG vs. hp”) # Add a title
  • 7. Available plotting systems • Base • lattice • ggplot2
  • 8. Base plotting system • Installed by default • Quickest way to visualise your data • Plot can be further updated using additional options
  • 10. Extended example plot(disp,mpg, main = "MPG vs. HP", # Add a title type = "p", col = "grey", # Change the color of the points pch = 16, # Change the plotting symbol see help(points) cex = 1, # Change size of plotting symbol xlab = “Horse power", # Add a label on the x-axis ylab = "Miles per Gallon", # Add a label on the y-axis bty = "n", # Remove the box around the plot #asp = 1, # Change the y/x aspect ratio see help(plot) font.axis = 1, # Change axis font to bold italic col.axis = "black", # Set the color of the axis xlim = c(20,500), # Set limits on x axis ylim = c(5,50), # Set limits on y axis las=1) # Make axis labels parallel to x-axis
  • 14. • Multivariate data • Uses formulas • Single function call The Lattice Plotting System
  • 15. The Lattice Plotting System • lattice: code for producing Trellis graphics, includes functions like xyplot(), bwplot(), levelplot() • Grid: implements a different graphics system and the lattice package are on top of it
  • 16. Main plot functions • xyplot(): scatterplots • bwplot(): boxplots • histogram(): histograms • stripplot(): a boxplot points • dotplot(): plot dots on "violin strings" • splom(): scatterplot matrix • levelplot(), contourplot(): for "image" data
  • 19. More examples • See lattice_example_1.R
  • 20. ggplot2 Plotting System • “Grammar of Graphics” by Leland Wilkinson, written by Hadley Wickham • Data must be a data frame • Uses grammar • Web site: http://ggplot2.org
  • 21. What is "Grammar of Graphics"? "In brief, the grammar tells us that a statistical graphic is a mapping from data to aesthetic attributes (colour, shape, size) of geometric objects (points, lines, bars). The plot may also contain statistical transformations of the data and is drawn on a specific coordinate system”- ggplot2 book
  • 22. qplot() and ggplot() • qplot() - works like plot() function in base plotting system data • should represent a data frame • aesthetic (size, colour, shape) and geoms (points, lines) • core of ggplot()
  • 23. qplot • qplot() - works like plot() function in base plotting system data • Should represent a data frame • aesthetic (size, colour) and geoms (points, lines) • Core of ggplot()
  • 27. Components of ggplot() • A data frame • aesthetic mapping (how data are mapped to colour and size) • geoms (points, shapes, lines) • facets • stats (binning, smoothing, quantiles) • scales (for aesthetic mapping, i.e. male=‘red’, female=‘blue’) • coordinate system Peng at al, Explanatory Data Analysis, Coursera online class
  • 28. Steps to plot with ggplot() • Plots are build up in layers • Plot the data • Overlay a summary • Add metadata and annotation Peng at al, Explanatory Data Analysis, Coursera online class
  • 29. Peng at al, Explanatory Data Analysis, Coursera online class
  • 30. Peng at al, Explanatory Data Analysis, Coursera online class Example # Basic: ggplot(mtcars, aes(hp, mpg)) + geom_point()
  • 31. Peng at al, Explanatory Data Analysis, Coursera online class Example # With color: ggplot(mtcars, aes(hp, mpg)) + geom_point(aes(color = cyl))
  • 32. Peng at al, Explanatory Data Analysis, Coursera online class Example # Boxplots: ggplot(data=mtcars, aes(hp, mpg)) + geom_boxplot(aes(as.factor(cyl)))
  • 33. Peng at al, Explanatory Data Analysis, Coursera online class Example # Faceting mtcars$cyl <- factor(mtcars$cyl) ggplot(data=mtcars, aes(hp, mpg)) + geom_point() + facet_grid(~ cyl)
  • 34. Peng at al, Explanatory Data Analysis, Coursera online class Example # Faceting mtcars$cyl <- factor(mtcars$cyl) ggplot(data=mtcars, aes(hp, mpg)) + geom_point() + facet_grid(~ cyl)
  • 35. Peng at al, Explanatory Data Analysis, Coursera online class Example ggplot(data=mtcars, aes(hp, mpg)) + geom_point() + facet_grid(~ cyl) + geom_smooth(colour = "blue", size = 1, method=lm)
  • 36. Resources • http://www.r-bloggers.com • http://revolutionanalytics.com • http://www.statmethods.net (Quick-R) • Coursera (Data Science Specialisation)