SlideShare a Scribd company logo
www.r-squared.in/git-hub
dataCrunch Data Visualization With R
Learn To Add Text Annotations To Plots
dataCrunch
Text Annotations
Slide 2
dataCrunchText Annotations: Objectives
Slide 3
In this section, we will learn to:
Add text annotations to the plots using
● text() function
● mtext() function
dataCrunchText Annotations: Introduction
Slide 4
The text() and the mtext() functions allow the user to add text annotations to the plots. While the
text() function places the text inside the plot, the mtext() function places the text on the margins of
the plot.
Below is the syntax for both the functions:
# the text function
text(x, y = NULL, labels = seq_along(x), adj = NULL,
pos = NULL, offset = 0.5, vfont = NULL,
cex = 1, col = NULL, font = NULL, ...)
# the mtext function
mtext(text, side = 3, line = 0, outer = FALSE, at = NA,
adj = NA, padj = NA, cex = NA, col = NA, font = NA, ...)
Let us explore each function and its arguments one by one:
dataCrunchText Annotations: text()
Slide 5
To add text annotations using the text() function, the following 3 arguments must be supplied:
● x: x axis coordinate
● y: y axis coordinate
● text: the text to be added to the plot
Below is a simple example:
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# add text
text(340, 30, "Sample Text")
The text appears at the coordinates (340, 30) on the
plot. Ensure that the text is enclosed in double quotes
and the coordinates provided are within the range of
the X and Y axis variable.
dataCrunchtext(): Color
Slide 6
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# modify the color of the text
text(340, 30, "Sample Text", col = "red")
Description
The color of the text can be modified using the col
argument in the text() function.
Code
dataCrunchtext(): Color
Slide 7
The below plot depicts the appearance of the text when different options for col are applied:
dataCrunchtext(): Font
Slide 8
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# modify the font of the text
text(340, 30, "Sample Text", font = 2)
Description
The font of the text can be modified using the font
argument in the text() function.
Code
dataCrunchtext(): Font
Slide 9
The below plot depicts the appearance of the text when different options for font are applied:
dataCrunchtext(): Font Family
Slide 10
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# modify the font family of the text
text(340, 30, "Sample Text", family = mono)
Description
The font family of the text can be modified using the
family argument in the text() function.
Code
dataCrunchtext(): Font Family
Slide 11
The below plot depicts the appearance of the text when different options for font family are applied:
dataCrunchtext(): Font Size
Slide 12
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# modify the size of the text
text(340, 30, "Sample Text", cex = 1.5)
Description
The size of the text can be modified using the cex
argument in the text() function.
Code
dataCrunchtext(): Font Size
Slide 13
The below plot depicts the appearance of the text when different options for font size are applied:
dataCrunchmtext(): Introduction
Slide 14
The mtext() function places text annotations on the margins of the plot instead of placing them
inside the plot. It allows the user to modify the location of the text in multiple ways and we will
explore them one by one.
Below is a simple example:
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# add text
mtext("Sample Text")
As you can see, the text is placed on
the margin of the plot and not inside
the plot. Next, we will learn to
specify the margin where the text
should be placed.
dataCrunchmtext(): Margin
Slide 15
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# specify the margin on which the text should appear
mtext("Sample Text", side = 1)
Description
The margin on which we want to place the
text can be specified using the side
argument. It takes 4 values from 1-4 each
representing one side of the plot.
Code
dataCrunchmtext(): Margin Options
Slide 16
The side argument can be used to specify the margin on which the text should be placed.
side Margin
1 Bottom
2 Left
3 Top
4 Right
dataCrunchmtext(): Margin
Slide 17
The below plot depicts the appearance of the text when different options for side are applied:
dataCrunchmtext(): Line
Slide 18
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# place the text away from the margin
mtext("Sample Text", line = 1)
Description
The line argument places the text at the
specified distance from the margin. The default
value is 0 and as the value increases the text
is placed farther from the margin and outside
the plot, and as the value decreases the text is
placed inside the plot and farther from the
margin.
Code
dataCrunchmtext(): Line
Slide 19
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# place the text away from the plot
mtext("Sample Text", line = -1)
Description
The line argument places the text inside the
plot when the values is less than zero.
Code
dataCrunchmtext(): Line
Slide 20
The below plot depicts the appearance of the text when different options for line are applied:
dataCrunchmtext(): adj
Slide 21
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# align the text to the left
mtext("Sample Text", adj= 0)
Description
The adj argument is used for horizontal
alignment of the text. If set to 0, the text will be
left aligned and at 1, it will be right aligned.
Code
dataCrunchmtext(): adj
Slide 22
# create a basic plot
plot(mtcars$disp, mtcars$mpg)
# align the text to the right
mtext("Sample Text", adj= 1)
Description
When the value is set to 1, the text will be right
aligned.
Code
dataCrunchmtext(): adj
Slide 23
The below plot depicts the appearance of the text when different options for text() are applied:
dataCrunch
Slide 24
Visit dataCrunch for
tutorials on:
→ R Programming
→ Business Analytics
→ Data Visualization
→ Web Applications
→ Package Development
→ Git & GitHub
Ad

More Related Content

What's hot (18)

Access intermediate 2010 final project new
Access intermediate 2010 final project newAccess intermediate 2010 final project new
Access intermediate 2010 final project new
clscott1
 
Chapter13 two-dimensional-array
Chapter13 two-dimensional-arrayChapter13 two-dimensional-array
Chapter13 two-dimensional-array
Deepak Singh
 
An introduction to matlab
An introduction to matlabAn introduction to matlab
An introduction to matlab
Dr. Andrew Wallace PhD
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In R
Rsquared Academy
 
Extreme querying with_analytics
Extreme querying with_analyticsExtreme querying with_analytics
Extreme querying with_analytics
Gary Myers
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
rumanatasnim415
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
rumanatasnim415
 
R studio
R studio R studio
R studio
Kinza Irshad
 
Excel/R
Excel/RExcel/R
Excel/R
Andrija Djurovic
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Sourabh Bhattacharya
 
R-Excel Integration
R-Excel IntegrationR-Excel Integration
R-Excel Integration
Andrija Djurovic
 
11)recap forms and queries
11)recap forms and queries11)recap forms and queries
11)recap forms and queries
panks172
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
Kamarudheen KV
 
Assigment 3
Assigment 3Assigment 3
Assigment 3
sukumaraser
 
Doc 20180130-wa0004
Doc 20180130-wa0004Doc 20180130-wa0004
Doc 20180130-wa0004
HarithaRanasinghe
 
Easy Blogging With Emacs -- Cheatsheet
Easy Blogging With Emacs -- CheatsheetEasy Blogging With Emacs -- Cheatsheet
Easy Blogging With Emacs -- Cheatsheet
Dashamir Hoxha
 
Matlab Visualizing Data
Matlab Visualizing DataMatlab Visualizing Data
Matlab Visualizing Data
DataminingTools Inc
 
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...
The Statistical and Applied Mathematical Sciences Institute
 

Similar to R Data Visualization: Learn To Add Text Annotations To Plots (20)

ExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptx
ExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptxExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptx
ExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptx
naufalmaulana43
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
SungaleliYuen
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
Sankhya_Analytics
 
R data types
R   data typesR   data types
R data types
Learnbay Datascience
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
C++ Homework Help
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
Text Layout With Core Text
Text Layout With Core TextText Layout With Core Text
Text Layout With Core Text
David Ding
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
Programming Homework Help
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
samdamfa
 
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvfmatplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
zmulani8
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
Paras Intotech
 
R Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible researchR Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible research
danxexcel
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
babuk110
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
Infinity Tech Solutions
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlow
Etsuji Nakai
 
R programming slides
R  programming slidesR  programming slides
R programming slides
Pankaj Saini
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
SharmilaMore5
 
Python Lab Manual for First year Engineering students
Python Lab Manual for First year Engineering studentsPython Lab Manual for First year Engineering students
Python Lab Manual for First year Engineering students
AkshayAgrawal34132
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
ExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptx
ExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptxExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptx
ExploringPrimsAlgorithmforMinimumSpanningTreesinC.pptx
naufalmaulana43
 
Text Layout With Core Text
Text Layout With Core TextText Layout With Core Text
Text Layout With Core Text
David Ding
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
samdamfa
 
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvfmatplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
zmulani8
 
R Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible researchR Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible research
danxexcel
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
babuk110
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlow
Etsuji Nakai
 
R programming slides
R  programming slidesR  programming slides
R programming slides
Pankaj Saini
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
SharmilaMore5
 
Python Lab Manual for First year Engineering students
Python Lab Manual for First year Engineering studentsPython Lab Manual for First year Engineering students
Python Lab Manual for First year Engineering students
AkshayAgrawal34132
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
Ad

More from Rsquared Academy (20)

Handling Date & Time in R
Handling Date & Time in RHandling Date & Time in R
Handling Date & Time in R
Rsquared Academy
 
Market Basket Analysis in R
Market Basket Analysis in RMarket Basket Analysis in R
Market Basket Analysis in R
Rsquared Academy
 
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
Rsquared Academy
 
Joining Data with dplyr
Joining Data with dplyrJoining Data with dplyr
Joining Data with dplyr
Rsquared Academy
 
Explore Data using dplyr
Explore Data using dplyrExplore Data using dplyr
Explore Data using dplyr
Rsquared Academy
 
Data Wrangling with dplyr
Data Wrangling with dplyrData Wrangling with dplyr
Data Wrangling with dplyr
Rsquared Academy
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with Pipes
Rsquared Academy
 
Introduction to tibbles
Introduction to tibblesIntroduction to tibbles
Introduction to tibbles
Rsquared Academy
 
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
Rsquared Academy
 
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
Rsquared Academy
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
Rsquared Academy
 
How to install & update R packages?
How to install & update R packages?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?How to get help in R?
How to get help in R?
Rsquared Academy
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Rsquared Academy
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
Rsquared Academy
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For BeginnersR Markdown Tutorial For Beginners
R Markdown Tutorial For Beginners
Rsquared Academy
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
Rsquared Academy
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
Rsquared Academy
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
Rsquared Academy
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
Rsquared Academy
 
Market Basket Analysis in R
Market Basket Analysis in RMarket Basket Analysis in R
Market Basket Analysis in R
Rsquared Academy
 
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
Rsquared Academy
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with Pipes
Rsquared Academy
 
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
Rsquared Academy
 
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
Rsquared Academy
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
Rsquared Academy
 
How to install & update R packages?
How to install & update R packages?How to install & update R packages?
How to install & update R packages?
Rsquared Academy
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
Rsquared Academy
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For BeginnersR Markdown Tutorial For Beginners
R Markdown Tutorial For Beginners
Rsquared Academy
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
Rsquared Academy
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
Rsquared Academy
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
Rsquared Academy
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
Rsquared Academy
 
Ad

Recently uploaded (20)

Volkswagen - Analyzing the World's Biggest Purchasing Process
Volkswagen - Analyzing the World's Biggest Purchasing ProcessVolkswagen - Analyzing the World's Biggest Purchasing Process
Volkswagen - Analyzing the World's Biggest Purchasing Process
Process mining Evangelist
 
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
Taqyea
 
vMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free DownloadvMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free Download
eyeskye547
 
Modern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx AaModern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx Aa
MuhammadAwaisKamboh
 
Suncorp - Integrating Process Mining at Australia's Largest Insurer
Suncorp - Integrating Process Mining at Australia's Largest InsurerSuncorp - Integrating Process Mining at Australia's Largest Insurer
Suncorp - Integrating Process Mining at Australia's Largest Insurer
Process mining Evangelist
 
Decision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdfDecision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdf
Saikat Basu
 
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
disnakertransjabarda
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
real illuminati Uganda agent 0782561496/0756664682
real illuminati Uganda agent 0782561496/0756664682real illuminati Uganda agent 0782561496/0756664682
real illuminati Uganda agent 0782561496/0756664682
way to join real illuminati Agent In Kampala Call/WhatsApp+256782561496/0756664682
 
How to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process miningHow to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process mining
Process mining Evangelist
 
Collibra DQ Installation setup and debug
Collibra DQ Installation setup and debugCollibra DQ Installation setup and debug
Collibra DQ Installation setup and debug
karthikprince20
 
03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia
Alexander Romero Arosquipa
 
spssworksho9035530-lva1-app6891 (1).pptx
spssworksho9035530-lva1-app6891 (1).pptxspssworksho9035530-lva1-app6891 (1).pptx
spssworksho9035530-lva1-app6891 (1).pptx
clarkraal
 
Process Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challengesProcess Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challenges
Process mining Evangelist
 
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
bastakwyry
 
Chapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhh
Chapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhhChapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhh
Chapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhh
ChrisjohnAlfiler
 
Automation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success storyAutomation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success story
Process mining Evangelist
 
717239550-Hotel-Management-Ppt-Final.pptx
717239550-Hotel-Management-Ppt-Final.pptx717239550-Hotel-Management-Ppt-Final.pptx
717239550-Hotel-Management-Ppt-Final.pptx
dharmendrasingh31102
 
50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd
emir73065
 
E-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahah
E-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahahE-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahah
E-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahah
RyanRahardjo2
 
Volkswagen - Analyzing the World's Biggest Purchasing Process
Volkswagen - Analyzing the World's Biggest Purchasing ProcessVolkswagen - Analyzing the World's Biggest Purchasing Process
Volkswagen - Analyzing the World's Biggest Purchasing Process
Process mining Evangelist
 
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
录取通知书加拿大TMU毕业证多伦多都会大学电子版毕业证成绩单
Taqyea
 
vMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free DownloadvMix Pro Crack + Serial Number Torrent free Download
vMix Pro Crack + Serial Number Torrent free Download
eyeskye547
 
Modern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx AaModern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx Aa
MuhammadAwaisKamboh
 
Suncorp - Integrating Process Mining at Australia's Largest Insurer
Suncorp - Integrating Process Mining at Australia's Largest InsurerSuncorp - Integrating Process Mining at Australia's Largest Insurer
Suncorp - Integrating Process Mining at Australia's Largest Insurer
Process mining Evangelist
 
Decision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdfDecision Trees in Artificial-Intelligence.pdf
Decision Trees in Artificial-Intelligence.pdf
Saikat Basu
 
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
disnakertransjabarda
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
How to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process miningHow to regulate and control your it-outsourcing provider with process mining
How to regulate and control your it-outsourcing provider with process mining
Process mining Evangelist
 
Collibra DQ Installation setup and debug
Collibra DQ Installation setup and debugCollibra DQ Installation setup and debug
Collibra DQ Installation setup and debug
karthikprince20
 
spssworksho9035530-lva1-app6891 (1).pptx
spssworksho9035530-lva1-app6891 (1).pptxspssworksho9035530-lva1-app6891 (1).pptx
spssworksho9035530-lva1-app6891 (1).pptx
clarkraal
 
Process Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challengesProcess Mining at Rabobank - Organizational challenges
Process Mining at Rabobank - Organizational challenges
Process mining Evangelist
 
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
bastakwyry
 
Chapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhh
Chapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhhChapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhh
Chapter-3-PROBLEM-SOLVING.pdf hhhhhhhhhh
ChrisjohnAlfiler
 
Automation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success storyAutomation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success story
Process mining Evangelist
 
717239550-Hotel-Management-Ppt-Final.pptx
717239550-Hotel-Management-Ppt-Final.pptx717239550-Hotel-Management-Ppt-Final.pptx
717239550-Hotel-Management-Ppt-Final.pptx
dharmendrasingh31102
 
50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd
emir73065
 
E-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahah
E-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahahE-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahah
E-Book-TOEFL-Masuk-PTN.pdf hahahahaahahahah
RyanRahardjo2
 

R Data Visualization: Learn To Add Text Annotations To Plots

  • 1. www.r-squared.in/git-hub dataCrunch Data Visualization With R Learn To Add Text Annotations To Plots
  • 3. dataCrunchText Annotations: Objectives Slide 3 In this section, we will learn to: Add text annotations to the plots using ● text() function ● mtext() function
  • 4. dataCrunchText Annotations: Introduction Slide 4 The text() and the mtext() functions allow the user to add text annotations to the plots. While the text() function places the text inside the plot, the mtext() function places the text on the margins of the plot. Below is the syntax for both the functions: # the text function text(x, y = NULL, labels = seq_along(x), adj = NULL, pos = NULL, offset = 0.5, vfont = NULL, cex = 1, col = NULL, font = NULL, ...) # the mtext function mtext(text, side = 3, line = 0, outer = FALSE, at = NA, adj = NA, padj = NA, cex = NA, col = NA, font = NA, ...) Let us explore each function and its arguments one by one:
  • 5. dataCrunchText Annotations: text() Slide 5 To add text annotations using the text() function, the following 3 arguments must be supplied: ● x: x axis coordinate ● y: y axis coordinate ● text: the text to be added to the plot Below is a simple example: # create a basic plot plot(mtcars$disp, mtcars$mpg) # add text text(340, 30, "Sample Text") The text appears at the coordinates (340, 30) on the plot. Ensure that the text is enclosed in double quotes and the coordinates provided are within the range of the X and Y axis variable.
  • 6. dataCrunchtext(): Color Slide 6 # create a basic plot plot(mtcars$disp, mtcars$mpg) # modify the color of the text text(340, 30, "Sample Text", col = "red") Description The color of the text can be modified using the col argument in the text() function. Code
  • 7. dataCrunchtext(): Color Slide 7 The below plot depicts the appearance of the text when different options for col are applied:
  • 8. dataCrunchtext(): Font Slide 8 # create a basic plot plot(mtcars$disp, mtcars$mpg) # modify the font of the text text(340, 30, "Sample Text", font = 2) Description The font of the text can be modified using the font argument in the text() function. Code
  • 9. dataCrunchtext(): Font Slide 9 The below plot depicts the appearance of the text when different options for font are applied:
  • 10. dataCrunchtext(): Font Family Slide 10 # create a basic plot plot(mtcars$disp, mtcars$mpg) # modify the font family of the text text(340, 30, "Sample Text", family = mono) Description The font family of the text can be modified using the family argument in the text() function. Code
  • 11. dataCrunchtext(): Font Family Slide 11 The below plot depicts the appearance of the text when different options for font family are applied:
  • 12. dataCrunchtext(): Font Size Slide 12 # create a basic plot plot(mtcars$disp, mtcars$mpg) # modify the size of the text text(340, 30, "Sample Text", cex = 1.5) Description The size of the text can be modified using the cex argument in the text() function. Code
  • 13. dataCrunchtext(): Font Size Slide 13 The below plot depicts the appearance of the text when different options for font size are applied:
  • 14. dataCrunchmtext(): Introduction Slide 14 The mtext() function places text annotations on the margins of the plot instead of placing them inside the plot. It allows the user to modify the location of the text in multiple ways and we will explore them one by one. Below is a simple example: # create a basic plot plot(mtcars$disp, mtcars$mpg) # add text mtext("Sample Text") As you can see, the text is placed on the margin of the plot and not inside the plot. Next, we will learn to specify the margin where the text should be placed.
  • 15. dataCrunchmtext(): Margin Slide 15 # create a basic plot plot(mtcars$disp, mtcars$mpg) # specify the margin on which the text should appear mtext("Sample Text", side = 1) Description The margin on which we want to place the text can be specified using the side argument. It takes 4 values from 1-4 each representing one side of the plot. Code
  • 16. dataCrunchmtext(): Margin Options Slide 16 The side argument can be used to specify the margin on which the text should be placed. side Margin 1 Bottom 2 Left 3 Top 4 Right
  • 17. dataCrunchmtext(): Margin Slide 17 The below plot depicts the appearance of the text when different options for side are applied:
  • 18. dataCrunchmtext(): Line Slide 18 # create a basic plot plot(mtcars$disp, mtcars$mpg) # place the text away from the margin mtext("Sample Text", line = 1) Description The line argument places the text at the specified distance from the margin. The default value is 0 and as the value increases the text is placed farther from the margin and outside the plot, and as the value decreases the text is placed inside the plot and farther from the margin. Code
  • 19. dataCrunchmtext(): Line Slide 19 # create a basic plot plot(mtcars$disp, mtcars$mpg) # place the text away from the plot mtext("Sample Text", line = -1) Description The line argument places the text inside the plot when the values is less than zero. Code
  • 20. dataCrunchmtext(): Line Slide 20 The below plot depicts the appearance of the text when different options for line are applied:
  • 21. dataCrunchmtext(): adj Slide 21 # create a basic plot plot(mtcars$disp, mtcars$mpg) # align the text to the left mtext("Sample Text", adj= 0) Description The adj argument is used for horizontal alignment of the text. If set to 0, the text will be left aligned and at 1, it will be right aligned. Code
  • 22. dataCrunchmtext(): adj Slide 22 # create a basic plot plot(mtcars$disp, mtcars$mpg) # align the text to the right mtext("Sample Text", adj= 1) Description When the value is set to 1, the text will be right aligned. Code
  • 23. dataCrunchmtext(): adj Slide 23 The below plot depicts the appearance of the text when different options for text() are applied:
  • 24. dataCrunch Slide 24 Visit dataCrunch for tutorials on: → R Programming → Business Analytics → Data Visualization → Web Applications → Package Development → Git & GitHub