SlideShare a Scribd company logo
www.r-squared.in/git-hub
dataCrunch Data Visualization With R
Learn To Modify Title, Axis Labels & Range
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
Title, Axis Labels & Range
Slide 3
dataCrunchTitle & Labels
Slide 4
In this section, we will learn to enhance the plot by adding/modifying the following features:
● Title
● Subtitle
● Axis Labels
● Axis Range
dataCrunchIntroduction
Slide 5
In the previous section, we created plots which did not have any title or labels. A new user of a plot
should know what the X and Y axis represent as well as the primary information being communicated
by the plot. The title, axis labels and range play an important role in making the plot holistic.
There are two ways of adding the above mentioned elements to a plot:
● Use the relevant arguments within the plot() function.
● Use the title() function.
We will explore both the methods one by one and you can choose the method that you find most
convenient. Let us begin by adding the features using the plot() function.
dataCrunchSyntax
Slide 6
Feature Argument Value Example
Title main String “Scatter Plot”
Subtitle sub String “Displacement vs Miles Per Gallon”
X Axis Label xlab String “Displacement”
Y Axis Label ylab String “Miles Per Gallon”
X Axis Range xlim Numeric Vector c(0, 500)
Y Axis Range ylim Numeric Vector c(0, 50)
dataCrunchTitle
Slide 7
# create a basic plot and add a title
plot(mtcars$disp, mtcars$mpg,
main = “Displacement vs Miles Per Gallon”)
Description
Use the main argument in the plot()
function to add a title to the plot. The title
must be enclosed in double quotes as it is a
string.
Code
dataCrunchSubtitle
Slide 8
# create a basic plot and add a subtitle
plot(mtcars$disp, mtcars$mpg,
sub = “Displacement vs Miles Per Gallon”)
Description
Use the sub argument in the plot()
function to add a subtitle to the plot. The
subtitle must be enclosed in double quotes
as it is a string.
Code
dataCrunchAxis Labels
Slide 9
# create a basic plot and add axis labels
plot(mtcars$disp, mtcars$mpg,
xlab = "Displacement",
ylab = "Miles Per Gallon")
Description
In all plots created till now, the axis labels
appear as mtcars$disp and mtcars$mpg.
It is not the most elegant way of labeling the
axis and it would make more sense to use
appropriate names. Use the xlab and ylab
arguments in the plot() function to add the
X and Y axis labels.
Code
dataCrunchAxis Range
Slide 10
# create a basic plot and modify axis range
plot(mtcars$disp, mtcars$mpg,
xlim = c(0, 600),
ylim = c(0, 50))
Description
The range of the axis can be modified using
the xlim and ylim arguments in the
plot() function. The lower and upper limit
for both the axis must be mentioned in a
numeric vector.
Code
dataCrunchSo far...
Slide 11
# create a plot with title, subtitle, axis
labels and range
plot(mtcars$disp, mtcars$mpg,
main = "Displacement vs Miles Per Gallon",
sub = "Scatter Plot",
xlab = "Displacement",
ylab = "Miles Per Gallon",
xlim = c(0, 600), ylim = c(0, 50))
Description
Let us create a plot that has all the features
that we have learnt so far:
Code
dataCrunchtitle() Function
Slide 12
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# add title and label using title() function
title(main = "Displacement vs Miles Per Gallon",
sub = "Scatter Plot",
xlab = "Displacement",
ylab = "Miles Per Gallon")
Description
We will add/modify the same set of features but
using the title() function instead of the
arguments in the plot() function but we will
continue to use the plot() function for creating the
basic plot.
Code
Oops.. We have a problem. If you have observed
carefully, the title() function has overwritten the
default axis labels created by the plot() function.
dataCrunchtitle() Function
Slide 13
# create a basic plot
plot(mtcars$disp, mtcars$mpg, ann = FALSE)
# add title and label using title() function
title(main = "Displacement vs Miles Per Gallon",
sub = "Scatter Plot",
xlab = "Displacement",
ylab = "Miles Per Gallon")
Description
Use the ann argument in the plot() function and
set it to FALSE to ensure that the plot() function
does not add the default labels.
Code
Note: The range of the axis cannot be modified
using the title() function.
dataCrunch
Slide 14
Visit dataCrunch for
tutorials on:
→ R Programming
→ Business Analytics
→ Data Visualization
→ Web Applications
→ Package Development
→ Git & GitHub
Ad

Recommended

Data Visualization With R: Learn To Combine Multiple Graphs
Data Visualization With R: Learn To Combine Multiple Graphs
Rsquared Academy
 
Data Visualization With R: Learn To Modify Color Of Plots
Data Visualization With R: Learn To Modify Color Of Plots
Rsquared Academy
 
Data Visualization With R: Introduction
Data Visualization With R: Introduction
Rsquared Academy
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
Data Visualization With R: Learn To Modify Font Of Graphical Parameters
Data Visualization With R: Learn To Modify Font Of Graphical Parameters
Rsquared Academy
 
R Data Visualization: Learn To Add Text Annotations To Plots
R Data Visualization: Learn To Add Text Annotations To Plots
Rsquared Academy
 
Data Visualization With R
Data Visualization With R
Rsquared Academy
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In R
Rsquared Academy
 
R Programming: Introduction to Vectors
R Programming: Introduction to Vectors
Rsquared Academy
 
R studio
R studio
Kinza Irshad
 
A quick introduction to R
A quick introduction to R
Angshuman Saha
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
The Statistical and Applied Mathematical Sciences Institute
 
Stack - Data Structure
Stack - Data Structure
Bhavesh Sanghvi
 
GNU octave
GNU octave
gauravmalav
 
Queue
Queue
A. S. M. Shafi
 
Basic of octave matlab programming language
Basic of octave matlab programming language
Aulia Khalqillah
 
Graph Plots in Matlab
Graph Plots in Matlab
DataminingTools Inc
 
Matlab Visualizing Data
Matlab Visualizing Data
DataminingTools Inc
 
Stack and queue
Stack and queue
Shakila Mahjabin
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
 
Hive function-cheat-sheet
Hive function-cheat-sheet
Dr. Volkan OBAN
 
Doc 20180130-wa0004
Doc 20180130-wa0004
HarithaRanasinghe
 
Team 6
Team 6
Sathasivam Rangasamy
 
Data structures
Data structures
Rokonuzzaman Rony
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 
Exploratory data analysis using r
Exploratory data analysis using r
Tahera Shaikh
 
Data visualization with R and ggplot2.docx
Data visualization with R and ggplot2.docx
kassaye4
 
Dplyr v2 . Exploratory data analysis.pdf
Dplyr v2 . Exploratory data analysis.pdf
PrinceUzair4
 
Dplyr v2 . Exploratory data analysis.pdf
Dplyr v2 . Exploratory data analysis.pdf
PrinceUzair4
 
Introduction to GGVIS Visualization
Introduction to GGVIS Visualization
HemantSingh311
 

More Related Content

What's hot (17)

R Programming: Introduction to Vectors
R Programming: Introduction to Vectors
Rsquared Academy
 
R studio
R studio
Kinza Irshad
 
A quick introduction to R
A quick introduction to R
Angshuman Saha
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
The Statistical and Applied Mathematical Sciences Institute
 
Stack - Data Structure
Stack - Data Structure
Bhavesh Sanghvi
 
GNU octave
GNU octave
gauravmalav
 
Queue
Queue
A. S. M. Shafi
 
Basic of octave matlab programming language
Basic of octave matlab programming language
Aulia Khalqillah
 
Graph Plots in Matlab
Graph Plots in Matlab
DataminingTools Inc
 
Matlab Visualizing Data
Matlab Visualizing Data
DataminingTools Inc
 
Stack and queue
Stack and queue
Shakila Mahjabin
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
 
Hive function-cheat-sheet
Hive function-cheat-sheet
Dr. Volkan OBAN
 
Doc 20180130-wa0004
Doc 20180130-wa0004
HarithaRanasinghe
 
Team 6
Team 6
Sathasivam Rangasamy
 
Data structures
Data structures
Rokonuzzaman Rony
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 

Similar to Data Visualization With R: Learn To Modify Title, Axis Labels & Range (20)

Exploratory data analysis using r
Exploratory data analysis using r
Tahera Shaikh
 
Data visualization with R and ggplot2.docx
Data visualization with R and ggplot2.docx
kassaye4
 
Dplyr v2 . Exploratory data analysis.pdf
Dplyr v2 . Exploratory data analysis.pdf
PrinceUzair4
 
Dplyr v2 . Exploratory data analysis.pdf
Dplyr v2 . Exploratory data analysis.pdf
PrinceUzair4
 
Introduction to GGVIS Visualization
Introduction to GGVIS Visualization
HemantSingh311
 
Unit---4.pdf how to gst du paper in this day and age
Unit---4.pdf how to gst du paper in this day and age
FireBolt6
 
M4_DAR_part1. module part 4 analystics with r
M4_DAR_part1. module part 4 analystics with r
LalithauLali
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptx
BhagyasriPatel2
 
Chart and graphs in R programming language
Chart and graphs in R programming language
CHANDAN KUMAR
 
4.Data-Visualization.pptx
4.Data-Visualization.pptx
PratyushJain37
 
Tools for research plotting
Tools for research plotting
Nimrita Koul
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in R
Ilya Zhbannikov
 
Tools for research plotting
Tools for research plotting
Nimrita Koul
 
Lab 2 - Managing Data in R Basic Conecpt.pptx
Lab 2 - Managing Data in R Basic Conecpt.pptx
noman297489
 
a9bf73_Introduction to Matplotlib01.pptx
a9bf73_Introduction to Matplotlib01.pptx
Rahidkhan10
 
R training5
R training5
Hellen Gakuruh
 
Murtaugh 2022 Appl Comp Genomics Tidyverse lecture.pptx-1.pptx
Murtaugh 2022 Appl Comp Genomics Tidyverse lecture.pptx-1.pptx
oliversen
 
R visualization: ggplot2, googlevis, plotly, igraph Overview
R visualization: ggplot2, googlevis, plotly, igraph Overview
Olga Scrivner
 
Concept mapping patient initials, age, gender and admitting d
Concept mapping patient initials, age, gender and admitting d
ARIV4
 
[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R
台灣資料科學年會
 
Exploratory data analysis using r
Exploratory data analysis using r
Tahera Shaikh
 
Data visualization with R and ggplot2.docx
Data visualization with R and ggplot2.docx
kassaye4
 
Dplyr v2 . Exploratory data analysis.pdf
Dplyr v2 . Exploratory data analysis.pdf
PrinceUzair4
 
Dplyr v2 . Exploratory data analysis.pdf
Dplyr v2 . Exploratory data analysis.pdf
PrinceUzair4
 
Introduction to GGVIS Visualization
Introduction to GGVIS Visualization
HemantSingh311
 
Unit---4.pdf how to gst du paper in this day and age
Unit---4.pdf how to gst du paper in this day and age
FireBolt6
 
M4_DAR_part1. module part 4 analystics with r
M4_DAR_part1. module part 4 analystics with r
LalithauLali
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptx
BhagyasriPatel2
 
Chart and graphs in R programming language
Chart and graphs in R programming language
CHANDAN KUMAR
 
4.Data-Visualization.pptx
4.Data-Visualization.pptx
PratyushJain37
 
Tools for research plotting
Tools for research plotting
Nimrita Koul
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in R
Ilya Zhbannikov
 
Tools for research plotting
Tools for research plotting
Nimrita Koul
 
Lab 2 - Managing Data in R Basic Conecpt.pptx
Lab 2 - Managing Data in R Basic Conecpt.pptx
noman297489
 
a9bf73_Introduction to Matplotlib01.pptx
a9bf73_Introduction to Matplotlib01.pptx
Rahidkhan10
 
Murtaugh 2022 Appl Comp Genomics Tidyverse lecture.pptx-1.pptx
Murtaugh 2022 Appl Comp Genomics Tidyverse lecture.pptx-1.pptx
oliversen
 
R visualization: ggplot2, googlevis, plotly, igraph Overview
R visualization: ggplot2, googlevis, plotly, igraph Overview
Olga Scrivner
 
Concept mapping patient initials, age, gender and admitting d
Concept mapping patient initials, age, gender and admitting d
ARIV4
 
[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R
台灣資料科學年會
 
Ad

More from Rsquared Academy (20)

Handling Date & Time in R
Handling Date & Time in R
Rsquared Academy
 
Market Basket Analysis in R
Market Basket Analysis in R
Rsquared Academy
 
Practical Introduction to Web scraping using R
Practical Introduction to Web scraping using R
Rsquared Academy
 
Joining Data with dplyr
Joining Data with dplyr
Rsquared Academy
 
Explore Data using dplyr
Explore Data using dplyr
Rsquared Academy
 
Data Wrangling with dplyr
Data Wrangling with dplyr
Rsquared Academy
 
Writing Readable Code with Pipes
Writing Readable Code with Pipes
Rsquared Academy
 
Introduction to tibbles
Introduction to tibbles
Rsquared Academy
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
Rsquared Academy
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into R
Rsquared Academy
 
Variables & Data Types in R
Variables & Data Types in R
Rsquared Academy
 
How to install & update R packages?
How to install & update R packages?
Rsquared Academy
 
How to get help in R?
How to get help in R?
Rsquared Academy
 
Introduction to R
Introduction to R
Rsquared Academy
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
Rsquared Academy
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For Beginners
Rsquared Academy
 
R Programming: Introduction to Matrices
R Programming: Introduction to Matrices
Rsquared Academy
 
R Programming: Variables & Data Types
R Programming: Variables & Data Types
Rsquared Academy
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
Rsquared Academy
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
Rsquared Academy
 
Market Basket Analysis in R
Market Basket Analysis in R
Rsquared Academy
 
Practical Introduction to Web scraping using R
Practical Introduction to Web scraping using R
Rsquared Academy
 
Writing Readable Code with Pipes
Writing Readable Code with Pipes
Rsquared Academy
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
Rsquared Academy
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into R
Rsquared Academy
 
Variables & Data Types in R
Variables & Data Types in R
Rsquared Academy
 
How to install & update R packages?
How to install & update R packages?
Rsquared Academy
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
Rsquared Academy
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For Beginners
Rsquared Academy
 
R Programming: Introduction to Matrices
R Programming: Introduction to Matrices
Rsquared Academy
 
R Programming: Variables & Data Types
R Programming: Variables & Data Types
Rsquared Academy
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
Rsquared Academy
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
Rsquared Academy
 
Ad

Recently uploaded (20)

Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
taqyea
 
The Influence off Flexible Work Policies
The Influence off Flexible Work Policies
sales480687
 
RESEARCH-FINAL-GROUP-3, about the final .pptx
RESEARCH-FINAL-GROUP-3, about the final .pptx
gwapokoha1
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
taqyed
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
Daily, Weekly, Monthly Report MTC March 2025.pptx
Daily, Weekly, Monthly Report MTC March 2025.pptx
PanjiDewaPamungkas1
 
Boost Business Efficiency with Professional Data Entry Services
Boost Business Efficiency with Professional Data Entry Services
eloiacs eloiacs
 
Presentation by Tariq & Mohammed (1).pptx
Presentation by Tariq & Mohammed (1).pptx
AbooddSandoqaa
 
Measurecamp Copenhagen - Consent Context
Measurecamp Copenhagen - Consent Context
Human37
 
Crafting-Research-Recommendations Grade 12.pptx
Crafting-Research-Recommendations Grade 12.pptx
DaryllWhere
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
NASA ESE Study Results v4 05.29.2020.pptx
NASA ESE Study Results v4 05.29.2020.pptx
CiroAlejandroCamacho
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
UPS and Big Data intro to Business Analytics.pptx
UPS and Big Data intro to Business Analytics.pptx
sanjum5582
 
Informatics Market Insights AI Workforce.pdf
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
@Reset-Password.pptx presentakh;kenvtion
@Reset-Password.pptx presentakh;kenvtion
MarkLariosa1
 
Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
taqyea
 
The Influence off Flexible Work Policies
The Influence off Flexible Work Policies
sales480687
 
RESEARCH-FINAL-GROUP-3, about the final .pptx
RESEARCH-FINAL-GROUP-3, about the final .pptx
gwapokoha1
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
taqyed
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
Daily, Weekly, Monthly Report MTC March 2025.pptx
Daily, Weekly, Monthly Report MTC March 2025.pptx
PanjiDewaPamungkas1
 
Boost Business Efficiency with Professional Data Entry Services
Boost Business Efficiency with Professional Data Entry Services
eloiacs eloiacs
 
Presentation by Tariq & Mohammed (1).pptx
Presentation by Tariq & Mohammed (1).pptx
AbooddSandoqaa
 
Measurecamp Copenhagen - Consent Context
Measurecamp Copenhagen - Consent Context
Human37
 
Crafting-Research-Recommendations Grade 12.pptx
Crafting-Research-Recommendations Grade 12.pptx
DaryllWhere
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
NASA ESE Study Results v4 05.29.2020.pptx
NASA ESE Study Results v4 05.29.2020.pptx
CiroAlejandroCamacho
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
UPS and Big Data intro to Business Analytics.pptx
UPS and Big Data intro to Business Analytics.pptx
sanjum5582
 
Informatics Market Insights AI Workforce.pdf
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
@Reset-Password.pptx presentakh;kenvtion
@Reset-Password.pptx presentakh;kenvtion
MarkLariosa1
 

Data Visualization With R: Learn To Modify Title, Axis Labels & Range

  • 1. www.r-squared.in/git-hub dataCrunch Data Visualization With R Learn To Modify Title, Axis Labels & Range
  • 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. dataCrunchTitle & Labels Slide 4 In this section, we will learn to enhance the plot by adding/modifying the following features: ● Title ● Subtitle ● Axis Labels ● Axis Range
  • 5. dataCrunchIntroduction Slide 5 In the previous section, we created plots which did not have any title or labels. A new user of a plot should know what the X and Y axis represent as well as the primary information being communicated by the plot. The title, axis labels and range play an important role in making the plot holistic. There are two ways of adding the above mentioned elements to a plot: ● Use the relevant arguments within the plot() function. ● Use the title() function. We will explore both the methods one by one and you can choose the method that you find most convenient. Let us begin by adding the features using the plot() function.
  • 6. dataCrunchSyntax Slide 6 Feature Argument Value Example Title main String “Scatter Plot” Subtitle sub String “Displacement vs Miles Per Gallon” X Axis Label xlab String “Displacement” Y Axis Label ylab String “Miles Per Gallon” X Axis Range xlim Numeric Vector c(0, 500) Y Axis Range ylim Numeric Vector c(0, 50)
  • 7. dataCrunchTitle Slide 7 # create a basic plot and add a title plot(mtcars$disp, mtcars$mpg, main = “Displacement vs Miles Per Gallon”) Description Use the main argument in the plot() function to add a title to the plot. The title must be enclosed in double quotes as it is a string. Code
  • 8. dataCrunchSubtitle Slide 8 # create a basic plot and add a subtitle plot(mtcars$disp, mtcars$mpg, sub = “Displacement vs Miles Per Gallon”) Description Use the sub argument in the plot() function to add a subtitle to the plot. The subtitle must be enclosed in double quotes as it is a string. Code
  • 9. dataCrunchAxis Labels Slide 9 # create a basic plot and add axis labels plot(mtcars$disp, mtcars$mpg, xlab = "Displacement", ylab = "Miles Per Gallon") Description In all plots created till now, the axis labels appear as mtcars$disp and mtcars$mpg. It is not the most elegant way of labeling the axis and it would make more sense to use appropriate names. Use the xlab and ylab arguments in the plot() function to add the X and Y axis labels. Code
  • 10. dataCrunchAxis Range Slide 10 # create a basic plot and modify axis range plot(mtcars$disp, mtcars$mpg, xlim = c(0, 600), ylim = c(0, 50)) Description The range of the axis can be modified using the xlim and ylim arguments in the plot() function. The lower and upper limit for both the axis must be mentioned in a numeric vector. Code
  • 11. dataCrunchSo far... Slide 11 # create a plot with title, subtitle, axis labels and range plot(mtcars$disp, mtcars$mpg, main = "Displacement vs Miles Per Gallon", sub = "Scatter Plot", xlab = "Displacement", ylab = "Miles Per Gallon", xlim = c(0, 600), ylim = c(0, 50)) Description Let us create a plot that has all the features that we have learnt so far: Code
  • 12. dataCrunchtitle() Function Slide 12 # create a basic plot plot(mtcars$disp, mtcars$mpg) # add title and label using title() function title(main = "Displacement vs Miles Per Gallon", sub = "Scatter Plot", xlab = "Displacement", ylab = "Miles Per Gallon") Description We will add/modify the same set of features but using the title() function instead of the arguments in the plot() function but we will continue to use the plot() function for creating the basic plot. Code Oops.. We have a problem. If you have observed carefully, the title() function has overwritten the default axis labels created by the plot() function.
  • 13. dataCrunchtitle() Function Slide 13 # create a basic plot plot(mtcars$disp, mtcars$mpg, ann = FALSE) # add title and label using title() function title(main = "Displacement vs Miles Per Gallon", sub = "Scatter Plot", xlab = "Displacement", ylab = "Miles Per Gallon") Description Use the ann argument in the plot() function and set it to FALSE to ensure that the plot() function does not add the default labels. Code Note: The range of the axis cannot be modified using the title() function.
  • 14. dataCrunch Slide 14 Visit dataCrunch for tutorials on: → R Programming → Business Analytics → Data Visualization → Web Applications → Package Development → Git & GitHub