SlideShare una empresa de Scribd logo
1 de 50
www.r-squared.in/git-hub
dataCrunch
Data Visualization With R
Learn To Combine Multiple Graphs
dataCrunchCourse Material
Slide 2
All the material related to this course are available at our Website
Slides can be viewed at SlideShare
Scripts can be downloaded from GitHub
Videos can be viewed on our Youtube Channel
dataCrunch
Layout
Slide 3
dataCrunchLayout: Objectives
Slide 4
In this section, we will learn to:
Combine multiple graphs in a single frame using the following functions:
● par() function
● layout() function
dataCrunchLayout: Introduction
Slide 5
Often, it is useful to have multiple plots in the same frame as it allows us to get a comprehensive view
of a particular variable or compare among different variables. The Graphics package offers two
methods to combine multiple plots.
The par() function can be used to set graphical parameters regarding plot layout using the mfcol and
mfrow arguments. The layout() function serves the same purpose but offers more flexibility by
allowing us to modify the height and width of rows and columns.
dataCrunchLayout: par()
Slide 6
The par() function allows us to customize the graphical parameters(title, axis, font, color, size) for a
particular session. For combining multiple plots, we can use the graphical parameters mfrow and
mfcol. These two parameters create a matrix of plots filled by rows and columns respectively. Let us
combine plots using both the above parameters.
Option Description Arguments
mfrow Fill by rows Number of rows and columns
mfcol Fill by columns Number of rows and columns
dataCrunchLayout: par(mfrow)
Slide 7
(a) mfrow
mfrow combines plots filled by rows i.e it takes two arguments, the number of rows and number of
columns and then starts filling the plots by row. Below is the syntax for mfrow:
Let us begin by combining 4 plots in 2 rows and 2 columns:
# mfrow syntax
mfrow(number of rows, number of columns)
dataCrunchRecipe 1: Code
Slide 8
Let us begin by combining 4 plots in 2 rows and 2 columns. The plots will be filled by rows as we are using
the mfrow function:
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 4 graphs to be combined and filled by rows
par(mfrow = c(2, 2))
# specify the graphs to be combined
plot(mtcars$mpg)
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchRecipe 1: Plot
Slide 9
dataCrunchRecipe 2: Code
Slide 10
Combine 2 plots in 1 row and 2 columns.
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 2 graphs to be combined and filled by rows
par(mfrow = c(1, 2))
# specify the graphs to be combined
hist(mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchRecipe 2: Plot
Slide 11
dataCrunchRecipe 3: Code
Slide 12
Combine 2 plots in 2 rows and 1 column
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 2 graphs to be combined and filled by rows
par(mfrow = c(2, 1))
# specify the graphs to be combined
hist(mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchRecipe 3: Plot
Slide 13
dataCrunchRecipe 4: Code
Slide 14
Combine 3 plots in 1 row and 3 columns
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 3 graphs to be combined and filled by rows
par(mfrow = c(1, 3))
# specify the graphs to be combined
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchRecipe 4: Plot
Slide 15
dataCrunchRecipe 5: Code
Slide 16
Combine 3 plots in 3 rows and 1 column
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 3 graphs to be combined and filled by rows
par(mfrow = c(3, 1))
# specify the graphs to be combined
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchRecipe 5: Plot
Slide 17
dataCrunchLayout: par(mfcol)
Slide 18
(a) mfcol
mfcol combines plots filled by columns i.e it takes two arguments, the number of rows and number of
columns and then starts filling the plots by columns. Below is the syntax for mfrow:
Let us begin by combining 4 plots in 2 rows and 2 columns:
# mfcol syntax
mfcol(number of rows, number of columns)
dataCrunchRecipe 6: Code
Slide 19
Combine 4 plots in 2 rows and 2 columns
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 4 graphs to be combined and filled by columns
par(mfcol = c(2, 2))
# specify the graphs to be combined
plot(mtcars$mpg)
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchRecipe 6: Plot
Slide 20
dataCrunchSpecial Cases
Slide 21
What happens if we specify lesser or more number of graphs? In the next two examples, we will
specify lesser or more number of graphs than we ask the par() function to combine. Let us see
what happens in such instances:
Case 1: Lesser number of graphs specified
We will specify that 4 plots need to be combined in 2 rows and 2 columns but provide only 3
graphs.
Case 2: Extra graph specified
We will specify that 4 plots need to be combined in 2 rows and 2 columns but specify 6 graphs
instead of 4.
dataCrunchSpecial Case 1: Code
Slide 22
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 4 graphs to be combined and filled by rows
par(mfrow = c(2, 2))
# specify the graphs to be combined
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchSpecial Case 1: Plot
Slide 23
dataCrunchSpecial Case 2: Code
Slide 24
# store the current parameter settings in init
init <- par(no.readonly=TRUE)
# specify that 4 graphs to be combined and filled by rows
par(mfrow = c(2, 2))
# specify the graphs to be combined
plot(mtcars$mpg)
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$disp, mtcars$mpg)
boxplot(mtcars$mpg)
# restore the setting stored in init
par(init)
dataCrunchSpecial Case 2: Plot
Slide 25
Frame 1 Frame 2
r-squaredCombining Graphs: layout()
Slide 26
At the core of the layout() function is a matrix. We communicate the structure in which the plots
must be combined using a matrix. As such, the layout function is more flexible compared to the par()
function.
Let us begin by combining 4 plots in a 2 row/2 column structure. We do this by creating a layout using
the matrix function.
Option Description Value
matrix Matrix specifying location of plots Matrix
widths Width of columns Vector
heights Heights of Rows Vector
dataCrunchRecipe 7: Code
Slide 27
Combine 4 plots in 2 rows/2 columns filled by rows
# specify the layout
# 4 plots to be combined in 2 row/ 2 columns and arranged by row
layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE))
# specify the 4 plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$mpg)
dataCrunchRecipe 7: Plot
Slide 28
dataCrunchRecipe 8: Code
Slide 29
Combine 4 plots in 2 rows/2 columns filled by columns
To fill the plots by column, we specify byrow = FALSE in the matrix.
# specify the layout
# 4 plots to be combined in 2 row/ 2 columns and filled by columns
layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = FALSE))
# specify the 4 plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$mpg)
dataCrunchRecipe 2: Plot
Slide 30
dataCrunchRecipe 9: Code
Slide 31
Combine 3 plots in 2 rows/2 columns filled by rows
The magic of the layout() function begins here. We want to combine 3 plots and the first plot should occupy both
the columns in row 1 and the next 2 plots should be in row 2. If you look at the matrix below, 1 is specified twice
and since the matrix is filled by row, it will occupy both the columns in the first row. Similarly the first plot will occupy
the entire first row. It will be crystal clear when you see the plot.
# specify the matrix
> matrix(c(1, 1, 2, 3), nrow = 2, byrow = TRUE)
[,1] [,2]
[1,] 1 1
[2,] 2 3
# 3 plots to be combined in 2 row/ 2 columns and arranged by row
layout(matrix(c(1, 1, 2, 3), nrow = 2, byrow = TRUE))
# specify the 3 plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
dataCrunchRecipe 9: Plot
Slide 32
dataCrunchRecipe 10: Code
Slide 33
Combine 3 plots in 2 rows/2 columns filled by rows
The plots must be filled by rows and the third plot must occupy both the columns of the second row while the other
two plots will be placed in the first row. The matrix would look like this:
# specify the matrix
> matrix(c(1, 2, 3, 3), nrow = 2, byrow = TRUE)
[,1] [,2]
[1,] 1 2
[2,] 3 3
# 3 plots to be combined in 2 row/ 2 columns and arranged by row
layout(matrix(c(1, 2, 3, 3), nrow = 2, byrow = TRUE))
# specify the 3 plots
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$disp, mtcars$mpg)
dataCrunchRecipe 10: Plot
Slide 34
dataCrunchRecipe 11: Code
Slide 35
Combine 3 plots in 2 rows/2 columns filled by columns
The plots must be filled by columns and the first plot must occupy both the rows of the first column
while the other two plots will be placed in the second column in two rows. The matrix would look
like this:
# specify the matrix
> matrix(c(1, 1, 2, 3), nrow = 2, byrow = FALSE)
[,1] [,2]
[1,] 1 2
[2,] 1 3
# 3 plots to be combined in 2 row/ 2 columns and arranged by columns
layout(matrix(c(1, 1, 2, 3), nrow = 2, byrow = FALSE))
# specify the 3 plots
hist(mtcars$mpg)
plot(mtcars$disp, mtcars$mpg)
boxplot(mtcars$mpg)
dataCrunchRecipe 11: Plot
Slide 36
dataCrunchRecipe 12: Code
Slide 37
Combine 3 plots in 2 rows/2 columns filled by columns
The plots must be filled by columns and the first plot must occupy both the rows of the second
column while the other two plots will be placed in the first column in two rows. The matrix would
look like this:
# specify the matrix
> matrix(c(1, 2, 3, 3), nrow = 2, byrow = FALSE)
[,1] [,2]
[1,] 1 3
[2,] 2 3
# 3 plots to be combined in 2 row/ 2 columns and arranged by columns
layout(matrix(c(1, 2, 3, 3), nrow = 2, byrow = FALSE))
# specify the 3 plots
boxplot(mtcars$mpg)
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
dataCrunchRecipe 12: Plot
Slide 38
dataCrunchlayout(): Widths
Slide 39
Widths
In all the layouts created so far, we have kept the size of the rows and columns equal. What if you
want to modify the width and height of the columns and rows? The widths and heights arguments
in the layout() function address the above mentioned issue. Let us check them out one by one:
The widths argument is used for specifying the width of the columns. Based on the number of
columns in the layout, you can specify the width of each column. Let us look at some examples.
dataCrunchRecipe 13: Code
Slide 40
Width of the 2nd column is twice the width of the 1st column
# specify the matrix
> matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE)
[,1] [,2]
[1,] 1 3
[2,] 2 4
# 4 plots to be combined in 2 row/ 2 columns and arranged by columns
layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE), widths = c(1, 3))
# specify the plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$mpg)
dataCrunchRecipe 13: Plot
Slide 41
dataCrunchRecipe 14: Code
Slide 42
Width of the 2nd column is twice that of the first and last column
# specify the matrix
> matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
# 6 plots to be combined in 2 row/ 3 columns and filled by rows
layout(matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE), widths = c(1, 2, 1))
# specify the plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
dataCrunchRecipe 14: Plot
Slide 43
dataCrunchlayout(): Heights
Slide 44
Heights
The heights arguments is used to modify the height of the rows and based on the number of
rows specified in the layout, we can specify the height of each row.
Height of the 2nd row is twice that of the first row
# 4 plots to be combined in 2 row/ 2 columns and filled by rows
layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE), heights= c(1, 2))
# specify the 4 plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$mpg)
dataCrunchRecipe 15: Plot
Slide 45
dataCrunchRecipe 16: Code
Slide 46
Height of the 3rd row is thrice that of the 1st and 2nd row
# specify the matrix
> matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE)
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
# 6 plots to be combined in 3 row/ 2 columns and arranged by rows
layout(matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE), heights= c(1, 1, 3))
# specify the plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
dataCrunchRecipe 16: Plot
Slide 47
dataCrunchPutting it all together...
Slide 48
Before we end this section, let us combine plots using both the widths and heights option.
# specify the matrix
> matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE)
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
# 6 plots to be combined in 3 row/ 2 columns and arranged by rows
layout(matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE), heights= c(1, 2, 1),
widths = c(2, 1))
# specify the 6 plots
plot(mtcars$disp, mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$mpg)
hist(mtcars$mpg)
boxplot(mtcars$mpg)
dataCrunchPlot
Slide 49
dataCrunch
Slide 50
Visit dataCrunch for
tutorials on:
→ R Programming
→ Business Analytics
→ Data Visualization
→ Web Applications
→ Package Development
→ Git & GitHub

Más contenido relacionado

La actualidad más candente

La actualidad más candente (16)

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 studio
R studio R studio
R studio
 
Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
 
Matlab Visualizing Data
Matlab Visualizing DataMatlab Visualizing Data
Matlab Visualizing Data
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Queues
QueuesQueues
Queues
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In R
 
Queue
QueueQueue
Queue
 
A Survey Of R Graphics
A Survey Of R GraphicsA Survey Of R Graphics
A Survey Of R Graphics
 
GNU octave
GNU octaveGNU octave
GNU octave
 
Basic of octave matlab programming language
Basic of octave matlab programming languageBasic of octave matlab programming language
Basic of octave matlab programming language
 
Doc 20180130-wa0004
Doc 20180130-wa0004Doc 20180130-wa0004
Doc 20180130-wa0004
 
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
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
 

Destacado

Demo deck liveexp
Demo deck liveexpDemo deck liveexp
Demo deck liveexp
Sean Royer
 
Introduccion a la generación de informes con R y LaTex
Introduccion a la generación de informes con R y LaTexIntroduccion a la generación de informes con R y LaTex
Introduccion a la generación de informes con R y LaTex
Antonio Contreras
 
Intern Project - Erika Goto
Intern Project - Erika GotoIntern Project - Erika Goto
Intern Project - Erika Goto
Erika Goto
 
Kerala livsetock trend state planning board 1966 to 2007
Kerala livsetock trend state planning board 1966 to 2007Kerala livsetock trend state planning board 1966 to 2007
Kerala livsetock trend state planning board 1966 to 2007
People's Archive of Rural India
 
The cosmopolitan corporation
The cosmopolitan corporationThe cosmopolitan corporation
The cosmopolitan corporation
Ranjith Thomas
 
Teaching Close Reading
Teaching Close ReadingTeaching Close Reading
Teaching Close Reading
theresa tinkle
 

Destacado (20)

Demo deck liveexp
Demo deck liveexpDemo deck liveexp
Demo deck liveexp
 
Introduccion a la generación de informes con R y LaTex
Introduccion a la generación de informes con R y LaTexIntroduccion a la generación de informes con R y LaTex
Introduccion a la generación de informes con R y LaTex
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
 
Instituto universitario de tecnologia
Instituto universitario de tecnologiaInstituto universitario de tecnologia
Instituto universitario de tecnologia
 
Hydrogeological report of Barazan Plateau, North Goa District
Hydrogeological report of Barazan Plateau, North Goa DistrictHydrogeological report of Barazan Plateau, North Goa District
Hydrogeological report of Barazan Plateau, North Goa District
 
Trn 12
Trn 12Trn 12
Trn 12
 
grlc Makes GitHub Taste Like Linked Data APIs
grlc Makes GitHub Taste Like Linked Data APIsgrlc Makes GitHub Taste Like Linked Data APIs
grlc Makes GitHub Taste Like Linked Data APIs
 
Intern Project - Erika Goto
Intern Project - Erika GotoIntern Project - Erika Goto
Intern Project - Erika Goto
 
Como es la cirugía de catarata
Como es la cirugía de catarataComo es la cirugía de catarata
Como es la cirugía de catarata
 
Kerala livsetock trend state planning board 1966 to 2007
Kerala livsetock trend state planning board 1966 to 2007Kerala livsetock trend state planning board 1966 to 2007
Kerala livsetock trend state planning board 1966 to 2007
 
Iran oil and gas infrastructure
Iran oil and gas infrastructure Iran oil and gas infrastructure
Iran oil and gas infrastructure
 
The cosmopolitan corporation
The cosmopolitan corporationThe cosmopolitan corporation
The cosmopolitan corporation
 
Joint Indonesia-UK Conference on Computational Chemistry 2015
Joint Indonesia-UK Conference on Computational Chemistry 2015Joint Indonesia-UK Conference on Computational Chemistry 2015
Joint Indonesia-UK Conference on Computational Chemistry 2015
 
Radar chart guide
Radar chart guideRadar chart guide
Radar chart guide
 
Teaching Close Reading
Teaching Close ReadingTeaching Close Reading
Teaching Close Reading
 
Gender and migration cwds key findings
Gender and migration cwds key findingsGender and migration cwds key findings
Gender and migration cwds key findings
 
Metabolic acidosis
Metabolic acidosisMetabolic acidosis
Metabolic acidosis
 
Perencanaan Pembangunan Prasarana Air untuk Lahan Perkebunan
Perencanaan Pembangunan Prasarana Air untuk Lahan PerkebunanPerencanaan Pembangunan Prasarana Air untuk Lahan Perkebunan
Perencanaan Pembangunan Prasarana Air untuk Lahan Perkebunan
 
Law of demand
Law of demandLaw of demand
Law of demand
 
Facial nerve injury
Facial nerve  injuryFacial nerve  injury
Facial nerve injury
 

Similar a Data Visualization With R: Learn To Combine Multiple Graphs

Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
ESWARANM92
 
Ashish garg research paper 660_CamReady
Ashish garg research paper 660_CamReadyAshish garg research paper 660_CamReady
Ashish garg research paper 660_CamReady
Ashish Garg
 

Similar a Data Visualization With R: Learn To Combine Multiple Graphs (20)

Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Data manipulation on r
Data manipulation on rData manipulation on r
Data manipulation on r
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Arrays with Numpy, Computer Graphics
Arrays with Numpy, Computer GraphicsArrays with Numpy, Computer Graphics
Arrays with Numpy, Computer Graphics
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
Fourier Transform Assignment Help
Fourier Transform Assignment HelpFourier Transform Assignment Help
Fourier Transform Assignment Help
 
pairs
pairspairs
pairs
 
"contour.py" module
"contour.py" module"contour.py" module
"contour.py" module
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
matlab Lesson 1
matlab Lesson 1matlab Lesson 1
matlab Lesson 1
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Ashish garg research paper 660_CamReady
Ashish garg research paper 660_CamReadyAshish garg research paper 660_CamReady
Ashish garg research paper 660_CamReady
 

Más de Rsquared Academy

Más de Rsquared Academy (20)

Handling Date & Time in R
Handling Date & Time in RHandling Date & Time in R
Handling Date & Time in R
 
Market Basket Analysis in R
Market Basket Analysis in RMarket Basket Analysis in R
Market Basket Analysis in R
 
Practical Introduction to Web scraping using R
Practical Introduction to Web scraping using RPractical Introduction to Web scraping using R
Practical Introduction to Web scraping using R
 
Joining Data with dplyr
Joining Data with dplyrJoining Data with dplyr
Joining Data with dplyr
 
Explore Data using dplyr
Explore Data using dplyrExplore Data using dplyr
Explore Data using dplyr
 
Data Wrangling with dplyr
Data Wrangling with dplyrData Wrangling with dplyr
Data Wrangling with dplyr
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with Pipes
 
Introduction to tibbles
Introduction to tibblesIntroduction to tibbles
Introduction to tibbles
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into RRead/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into R
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
 
How to install & update R packages?
How to install & update R packages?How to install & update R packages?
How to install & update R packages?
 
How to get help in R?
How to get help in R?How to get help in R?
How to get help in R?
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For BeginnersR Markdown Tutorial For Beginners
R Markdown Tutorial For Beginners
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
 

Último

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
Lars Albertsson
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
MarinCaroMartnezBerg
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
shambhavirathore45
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
JohnnyPlasten
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 

Último (20)

BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
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
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 

Data Visualization With R: Learn To Combine Multiple Graphs

  • 2. dataCrunchCourse Material Slide 2 All the material related to this course are available at our Website Slides can be viewed at SlideShare Scripts can be downloaded from GitHub Videos can be viewed on our Youtube Channel
  • 4. dataCrunchLayout: Objectives Slide 4 In this section, we will learn to: Combine multiple graphs in a single frame using the following functions: ● par() function ● layout() function
  • 5. dataCrunchLayout: Introduction Slide 5 Often, it is useful to have multiple plots in the same frame as it allows us to get a comprehensive view of a particular variable or compare among different variables. The Graphics package offers two methods to combine multiple plots. The par() function can be used to set graphical parameters regarding plot layout using the mfcol and mfrow arguments. The layout() function serves the same purpose but offers more flexibility by allowing us to modify the height and width of rows and columns.
  • 6. dataCrunchLayout: par() Slide 6 The par() function allows us to customize the graphical parameters(title, axis, font, color, size) for a particular session. For combining multiple plots, we can use the graphical parameters mfrow and mfcol. These two parameters create a matrix of plots filled by rows and columns respectively. Let us combine plots using both the above parameters. Option Description Arguments mfrow Fill by rows Number of rows and columns mfcol Fill by columns Number of rows and columns
  • 7. dataCrunchLayout: par(mfrow) Slide 7 (a) mfrow mfrow combines plots filled by rows i.e it takes two arguments, the number of rows and number of columns and then starts filling the plots by row. Below is the syntax for mfrow: Let us begin by combining 4 plots in 2 rows and 2 columns: # mfrow syntax mfrow(number of rows, number of columns)
  • 8. dataCrunchRecipe 1: Code Slide 8 Let us begin by combining 4 plots in 2 rows and 2 columns. The plots will be filled by rows as we are using the mfrow function: # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 4 graphs to be combined and filled by rows par(mfrow = c(2, 2)) # specify the graphs to be combined plot(mtcars$mpg) plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 10. dataCrunchRecipe 2: Code Slide 10 Combine 2 plots in 1 row and 2 columns. # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 2 graphs to be combined and filled by rows par(mfrow = c(1, 2)) # specify the graphs to be combined hist(mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 12. dataCrunchRecipe 3: Code Slide 12 Combine 2 plots in 2 rows and 1 column # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 2 graphs to be combined and filled by rows par(mfrow = c(2, 1)) # specify the graphs to be combined hist(mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 14. dataCrunchRecipe 4: Code Slide 14 Combine 3 plots in 1 row and 3 columns # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 3 graphs to be combined and filled by rows par(mfrow = c(1, 3)) # specify the graphs to be combined plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 16. dataCrunchRecipe 5: Code Slide 16 Combine 3 plots in 3 rows and 1 column # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 3 graphs to be combined and filled by rows par(mfrow = c(3, 1)) # specify the graphs to be combined plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 18. dataCrunchLayout: par(mfcol) Slide 18 (a) mfcol mfcol combines plots filled by columns i.e it takes two arguments, the number of rows and number of columns and then starts filling the plots by columns. Below is the syntax for mfrow: Let us begin by combining 4 plots in 2 rows and 2 columns: # mfcol syntax mfcol(number of rows, number of columns)
  • 19. dataCrunchRecipe 6: Code Slide 19 Combine 4 plots in 2 rows and 2 columns # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 4 graphs to be combined and filled by columns par(mfcol = c(2, 2)) # specify the graphs to be combined plot(mtcars$mpg) plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 21. dataCrunchSpecial Cases Slide 21 What happens if we specify lesser or more number of graphs? In the next two examples, we will specify lesser or more number of graphs than we ask the par() function to combine. Let us see what happens in such instances: Case 1: Lesser number of graphs specified We will specify that 4 plots need to be combined in 2 rows and 2 columns but provide only 3 graphs. Case 2: Extra graph specified We will specify that 4 plots need to be combined in 2 rows and 2 columns but specify 6 graphs instead of 4.
  • 22. dataCrunchSpecial Case 1: Code Slide 22 # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 4 graphs to be combined and filled by rows par(mfrow = c(2, 2)) # specify the graphs to be combined plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 23. dataCrunchSpecial Case 1: Plot Slide 23
  • 24. dataCrunchSpecial Case 2: Code Slide 24 # store the current parameter settings in init init <- par(no.readonly=TRUE) # specify that 4 graphs to be combined and filled by rows par(mfrow = c(2, 2)) # specify the graphs to be combined plot(mtcars$mpg) plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$disp, mtcars$mpg) boxplot(mtcars$mpg) # restore the setting stored in init par(init)
  • 25. dataCrunchSpecial Case 2: Plot Slide 25 Frame 1 Frame 2
  • 26. r-squaredCombining Graphs: layout() Slide 26 At the core of the layout() function is a matrix. We communicate the structure in which the plots must be combined using a matrix. As such, the layout function is more flexible compared to the par() function. Let us begin by combining 4 plots in a 2 row/2 column structure. We do this by creating a layout using the matrix function. Option Description Value matrix Matrix specifying location of plots Matrix widths Width of columns Vector heights Heights of Rows Vector
  • 27. dataCrunchRecipe 7: Code Slide 27 Combine 4 plots in 2 rows/2 columns filled by rows # specify the layout # 4 plots to be combined in 2 row/ 2 columns and arranged by row layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE)) # specify the 4 plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$mpg)
  • 29. dataCrunchRecipe 8: Code Slide 29 Combine 4 plots in 2 rows/2 columns filled by columns To fill the plots by column, we specify byrow = FALSE in the matrix. # specify the layout # 4 plots to be combined in 2 row/ 2 columns and filled by columns layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = FALSE)) # specify the 4 plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$mpg)
  • 31. dataCrunchRecipe 9: Code Slide 31 Combine 3 plots in 2 rows/2 columns filled by rows The magic of the layout() function begins here. We want to combine 3 plots and the first plot should occupy both the columns in row 1 and the next 2 plots should be in row 2. If you look at the matrix below, 1 is specified twice and since the matrix is filled by row, it will occupy both the columns in the first row. Similarly the first plot will occupy the entire first row. It will be crystal clear when you see the plot. # specify the matrix > matrix(c(1, 1, 2, 3), nrow = 2, byrow = TRUE) [,1] [,2] [1,] 1 1 [2,] 2 3 # 3 plots to be combined in 2 row/ 2 columns and arranged by row layout(matrix(c(1, 1, 2, 3), nrow = 2, byrow = TRUE)) # specify the 3 plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg)
  • 33. dataCrunchRecipe 10: Code Slide 33 Combine 3 plots in 2 rows/2 columns filled by rows The plots must be filled by rows and the third plot must occupy both the columns of the second row while the other two plots will be placed in the first row. The matrix would look like this: # specify the matrix > matrix(c(1, 2, 3, 3), nrow = 2, byrow = TRUE) [,1] [,2] [1,] 1 2 [2,] 3 3 # 3 plots to be combined in 2 row/ 2 columns and arranged by row layout(matrix(c(1, 2, 3, 3), nrow = 2, byrow = TRUE)) # specify the 3 plots hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$disp, mtcars$mpg)
  • 35. dataCrunchRecipe 11: Code Slide 35 Combine 3 plots in 2 rows/2 columns filled by columns The plots must be filled by columns and the first plot must occupy both the rows of the first column while the other two plots will be placed in the second column in two rows. The matrix would look like this: # specify the matrix > matrix(c(1, 1, 2, 3), nrow = 2, byrow = FALSE) [,1] [,2] [1,] 1 2 [2,] 1 3 # 3 plots to be combined in 2 row/ 2 columns and arranged by columns layout(matrix(c(1, 1, 2, 3), nrow = 2, byrow = FALSE)) # specify the 3 plots hist(mtcars$mpg) plot(mtcars$disp, mtcars$mpg) boxplot(mtcars$mpg)
  • 37. dataCrunchRecipe 12: Code Slide 37 Combine 3 plots in 2 rows/2 columns filled by columns The plots must be filled by columns and the first plot must occupy both the rows of the second column while the other two plots will be placed in the first column in two rows. The matrix would look like this: # specify the matrix > matrix(c(1, 2, 3, 3), nrow = 2, byrow = FALSE) [,1] [,2] [1,] 1 3 [2,] 2 3 # 3 plots to be combined in 2 row/ 2 columns and arranged by columns layout(matrix(c(1, 2, 3, 3), nrow = 2, byrow = FALSE)) # specify the 3 plots boxplot(mtcars$mpg) plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg)
  • 39. dataCrunchlayout(): Widths Slide 39 Widths In all the layouts created so far, we have kept the size of the rows and columns equal. What if you want to modify the width and height of the columns and rows? The widths and heights arguments in the layout() function address the above mentioned issue. Let us check them out one by one: The widths argument is used for specifying the width of the columns. Based on the number of columns in the layout, you can specify the width of each column. Let us look at some examples.
  • 40. dataCrunchRecipe 13: Code Slide 40 Width of the 2nd column is twice the width of the 1st column # specify the matrix > matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE) [,1] [,2] [1,] 1 3 [2,] 2 4 # 4 plots to be combined in 2 row/ 2 columns and arranged by columns layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE), widths = c(1, 3)) # specify the plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$mpg)
  • 42. dataCrunchRecipe 14: Code Slide 42 Width of the 2nd column is twice that of the first and last column # specify the matrix > matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE) [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 # 6 plots to be combined in 2 row/ 3 columns and filled by rows layout(matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE), widths = c(1, 2, 1)) # specify the plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg)
  • 44. dataCrunchlayout(): Heights Slide 44 Heights The heights arguments is used to modify the height of the rows and based on the number of rows specified in the layout, we can specify the height of each row. Height of the 2nd row is twice that of the first row # 4 plots to be combined in 2 row/ 2 columns and filled by rows layout(matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE), heights= c(1, 2)) # specify the 4 plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$mpg)
  • 46. dataCrunchRecipe 16: Code Slide 46 Height of the 3rd row is thrice that of the 1st and 2nd row # specify the matrix > matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE) [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 # 6 plots to be combined in 3 row/ 2 columns and arranged by rows layout(matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE), heights= c(1, 1, 3)) # specify the plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg)
  • 48. dataCrunchPutting it all together... Slide 48 Before we end this section, let us combine plots using both the widths and heights option. # specify the matrix > matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE) [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 # 6 plots to be combined in 3 row/ 2 columns and arranged by rows layout(matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE), heights= c(1, 2, 1), widths = c(2, 1)) # specify the 6 plots plot(mtcars$disp, mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg) plot(mtcars$mpg) hist(mtcars$mpg) boxplot(mtcars$mpg)
  • 50. dataCrunch Slide 50 Visit dataCrunch for tutorials on: → R Programming → Business Analytics → Data Visualization → Web Applications → Package Development → Git & GitHub