SlideShare a Scribd company logo
Charts and Graphs-
R Programming
Introduction
 Since we know that a huge amount of data is generated when
it comes to interpreting any sector
 To acquire significant insights, it is usually preferable to depict
data through charts and graphs rather than scanning large
Excel sheets.
 The R programming language is mostly used to depict data
graphically in software for statistics and data analytics.
 The R programming language includes some simple and easy
techniques for converting data into visually appealing features
such as graphs and charts.
 In R, charts and graphs are used to graphically depict the
data.
 R Programming language has numerous libraries to create
charts and graphs.
 There are numerous types of charts and graphs are present in
R language such as pie chart, scatter graph, bar plot, box plot,
mosaic plot, dot chart, coplot, histogram, etc.
Pie Chart
 A pie chart is a visual depiction of values as colored slices of a
circle.
 The slices are identified, and the graphic also shows the
numbers that correlate to each slice.
 The pie chart is made in R using the pie() function, which
requires a vector input of positive values.
 The extra options are used to customize labels, color, and
title, among other things.
 Syntax:
pie(x, labels, radius, main, col, clockwise)
vector
Description
radius of
the circle
Direction
color
palette
Title
Here,
 x indicates a vector that contain numerical values.
 labels is used to describe the slices.
 radius indicates the radius of the circle of the pie chart.
(value between −1 and +1).
 The chart's title is indicated by the main.
 The color palette is indicated by col.
 The logical value clockwise indicates whether the slices are
drawn clockwise or anticlockwise.
Example-1
We can create a very simple pie-chart with the help of only two
parameters such as the input vector and labels.
# Firstly we Create data i.e. vector for the chart.
x <- c(35, 60, 20, 40)
# After that naming labels of slices
labels <- c(“INDIA", "NEW YORK", “NEW DELHI", "MUMBAI")
# Call pie() function to Plot the chart
pie(x,labels)
 After executing these commands
R Console shows the given chart.
Example- 2
#The below script will create a pie chart and save the pie chart in
the current R working directory.
x <- c(35, 60, 20, 40)
labels <- c(“KANPUR", “BAREILLY", “NEW DELHI", "MUMBAI")
# Call png() function to give the chart file name.
png(file = "city.png")
pie(x,labels)
# To Save the file.
dev.off()
Example- 3
 #We can expand the features of the pie chart by adding more parameters
to the function. The below script shows it.
 pie(x, labels, main="City Pie Chart")
Example- 4
 pie(x,labels, radius= -1, main="City Pie Chart")
Example- 5
 pie(x, labels, radius= 1, main="City Pie Chart", col="RED")
 Note: For rainbow color pallet, Use rainbow
function.
3D Pie Chart
 We can also draw pie chart with 3 dimensions i.e. 3D using
additional packages.
 plotrix package has a function called pie3D() that is used for
creating 3D pie chart.
Example- 6
# Install Package
Install.packages(“plotrix”)
# Get the library.
library(plotrix)
# Create data for the graph.
x <- c(35, 60, 20, 40)
labels <- c(“KANPUR", “BAREILLY", “NEW DELHI",
"MUMBAI")
pie3D(x,labels = lbl,explode = 0.1, main = "Pie Chart of
Countries ")
Histograms
 A histogram represents the frequencies of values of a variable
bucketed into ranges.
 Histogram is similar to bar chat but the difference is it groups
the values into continuous ranges i.e. In a histogram, there
are no gaps between the bars, unlike a bar graph.
 Each bar in histogram represents the height of the number of
values present in that range.
 R creates histogram using hist() function.
 This function takes a vector as an input and uses some more
parameters to plot histograms.
 We Use histograms when we have continuous
measurements and want to understand the distribution of
values and look for outliers.
 Syntax:
hist(v,main,xlab,xlim,ylim,breaks,col,border)
vector
Description
description
of x-axis
width of
each bar
range of values on
the y-axis.
range of values on
the x-axis
color
palette
set border
color
Here
 v indicates vector that contain numeric values.
 Title of the chart is indicated by main
 col parameter is used to set color of the bars.
 To set border color of each bar, border parameter is used.
 xlab is used to give description of x-axis.
 xlim and ylim are used to specify the range of values on the x-
axis and y-axis respectively.
 breaks is used to mention the width of each bar.
Example- 1
 # Create histogram
 # Create data for the graph.
v <- c(7,11,19,7,40,12,22,31,44,55,43)
 # Create the histogram.
hist( v, xlab = "Weight", col = "yellow",
border = "blue")
Example- 2
 The xlim and ylim parameters can be used to set the range of
values allowed in the X and Y axes, respectively.
 Breaks can be used to determine the width of each bar.
v <- c(7,11,19,7,40,12,22,31,44,55,43)
hist(v,xlab = "Weight",col = "green",border =
"red",xlim = c(0,40), ylim = c(0,5), breaks = 5)
Bar Charts
 A bar chart depicts data as rectangular bars whose length is
proportionate to the variable's value.
 The function barplot() in R is used to make bar charts.
 In a bar chart, R can create both vertical and horizontal bars.
 Each of the bars in a bar chart can be colored differently.
 Syntax:
barplot(H,xlab,ylab,main, names.arg,col)
vector
label for x
axis
width of
each bar
label for y
axis
Title
names appearing
under each bar
colors to
the bars
Here,
 H indicates vector or matrix that contain numeric values.
 xlab is the label for x axis.
 ylab is the label for y axis.
 main is the title of the bar chart.
 names.arg is a vector of names appearing under each bar.
 col is used to give colors to the bars in the graph.
Example- 1
 Create a simple bar chart
 # Create the data for the bar chart
 H <- c(9,15,23,13,22)
 # Plot the bar chart
 barplot(H)
Example- 2
Create a simple bar chart using vector and names of each bar.
 # Create the data for the bar chart
H <- c(9,15,23,13,22)
names <- c("March","April","May","June","July")
 # Plot the bar chart
barplot(H,names.arg = names)
Example- 3
 Create a bar chart using other parameters.
H <- c(9,15,23,13,22)
names <- c("March","April","May","June","July")
barplot(H,names.arg=names,xlab="Months",ylab=“
Expenditure",col="yellow", main="Expenditure
chart",border="black")
Or
We also use parameters in this sequence.
barplot(H,xlab="Months",ylab="Expenditure",main="Expenditur
e chart", names.arg = names, col= "blue")
Line Graph
 A line chart is a graph that connects a set of points by
connecting them with line segments.
 These points are sorted according to the value of one of their
coordinates (typically the x-coordinate).
 Line charts are commonly used to identify data trends.
 The line graph was created using R's plot() function.
 Syntax:
plot(v, type, main, col, xlab, ylab)
vector
Title
Draw points
or lines
label for
x axis
label for y
axis
colors to both the points
and lines
Here
 The numeric values are stored in vector V
 Type takes value "p" is used to draw only points, "l" is used to
draw just lines, and "o" is used to draw both points and lines.
 The x axis is labeled as xlab.
 The y axis label is ylab.
 The main is the chart's title.
 The col is used to color both the points and the lines.
Example- 1
We can create a simple line chart using two parameters the
input vector and the type parameter as “o".
v <- c(10,15,22,32)
plot (v,type = “o”)
Example - 2
 Create using other parameters
v <- c(10,15,11,17,28)
plot (v, main = “Line Graph”, xlab = “Months”, ylab =
“Expenditure”, type = “o”, col = “RED”)
Example - 3
 Using lines()function, More than one line can be
drawn on the same chart
v <- c(7,12,28,3,41)
t <- c(14,7,6,19,3)
plot(v,type = "o",col = “blue", xlab
= "Months", ylab = “Expenditure",
main = “Expenditure chart")
lines(t, type = "o", col = “yellow")
Chart and graphs in R programming language

More Related Content

What's hot (20)

Data frame operations
Data frame operations
19MSS011dhanyatha
 
Python exception handling
Python exception handling
Mohammed Sikander
 
Strings in python
Strings in python
Prabhakaran V M
 
Data mining: Classification and prediction
Data mining: Classification and prediction
DataminingTools Inc
 
3. R- list and data frame
3. R- list and data frame
krishna singh
 
Decision trees in Machine Learning
Decision trees in Machine Learning
Mohammad Junaid Khan
 
Exploratory data analysis with Python
Exploratory data analysis with Python
Davis David
 
R Programming: Introduction To R Packages
R Programming: Introduction To R Packages
Rsquared Academy
 
Data visualization using R
Data visualization using R
Ummiya Mohammedi
 
Python programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
3.5 model based clustering
3.5 model based clustering
Krish_ver2
 
Integrity Constraints
Integrity Constraints
madhav bansal
 
Union in C programming
Union in C programming
Kamal Acharya
 
K mean-clustering algorithm
K mean-clustering algorithm
parry prabhu
 
Unit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
Relational algebra in dbms
Relational algebra in dbms
Vignesh Saravanan
 
Attribute oriented analysis
Attribute oriented analysis
Hirra Sultan
 
Data preprocessing in Machine learning
Data preprocessing in Machine learning
pyingkodi maran
 
Unit I Role of Mathematical Model in BI and BI Cycle.pdf
Unit I Role of Mathematical Model in BI and BI Cycle.pdf
ShivarkarSandip
 
R programming
R programming
Shantanu Patil
 
Data mining: Classification and prediction
Data mining: Classification and prediction
DataminingTools Inc
 
3. R- list and data frame
3. R- list and data frame
krishna singh
 
Decision trees in Machine Learning
Decision trees in Machine Learning
Mohammad Junaid Khan
 
Exploratory data analysis with Python
Exploratory data analysis with Python
Davis David
 
R Programming: Introduction To R Packages
R Programming: Introduction To R Packages
Rsquared Academy
 
Data visualization using R
Data visualization using R
Ummiya Mohammedi
 
3.5 model based clustering
3.5 model based clustering
Krish_ver2
 
Integrity Constraints
Integrity Constraints
madhav bansal
 
Union in C programming
Union in C programming
Kamal Acharya
 
K mean-clustering algorithm
K mean-clustering algorithm
parry prabhu
 
Attribute oriented analysis
Attribute oriented analysis
Hirra Sultan
 
Data preprocessing in Machine learning
Data preprocessing in Machine learning
pyingkodi maran
 
Unit I Role of Mathematical Model in BI and BI Cycle.pdf
Unit I Role of Mathematical Model in BI and BI Cycle.pdf
ShivarkarSandip
 

Similar to Chart and graphs in R programming language (20)

R programming.pptx r language easy concept
R programming.pptx r language easy concept
MuhammadjunaidgulMuh1
 
Exploratory data analysis using r
Exploratory data analysis using r
Tahera Shaikh
 
R graphics
R graphics
DHIVYADEVAKI
 
Lectures r-graphics
Lectures r-graphics
etyca
 
statistical computation using R- an intro..
statistical computation using R- an intro..
Kamarudheen KV
 
pie chart ppt.pdf ppt on pie chart. Veri formal
pie chart ppt.pdf ppt on pie chart. Veri formal
rjyotisingh123
 
Exploratory Data Analysis
Exploratory Data Analysis
Umair Shafique
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
R training5
R training5
Hellen Gakuruh
 
Introduction to r
Introduction to r
Golden Julie Jesus
 
Line graph bar graph
Line graph bar graph
Ayesha Arshad
 
Lecture_3.pptx
Lecture_3.pptx
SungaleliYuen
 
Line & Bar Graphs
Line & Bar Graphs
herbison
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
1. Introduction.pptx
1. Introduction.pptx
SungaleliYuen
 
visual representation with BOX PLOT,BAR PLOTS
visual representation with BOX PLOT,BAR PLOTS
anjanasharma77573
 
Domain and Range of a Function- Day3.pptx
Domain and Range of a Function- Day3.pptx
lorryswift847
 
Graphing Data
Graphing Data
shas595
 
Lesson 3
Lesson 3
Vinnu Vinay
 
M2M_250327_22434hjjik7_250411_183538.pdf
M2M_250327_22434hjjik7_250411_183538.pdf
HebaEng
 
R programming.pptx r language easy concept
R programming.pptx r language easy concept
MuhammadjunaidgulMuh1
 
Exploratory data analysis using r
Exploratory data analysis using r
Tahera Shaikh
 
Lectures r-graphics
Lectures r-graphics
etyca
 
statistical computation using R- an intro..
statistical computation using R- an intro..
Kamarudheen KV
 
pie chart ppt.pdf ppt on pie chart. Veri formal
pie chart ppt.pdf ppt on pie chart. Veri formal
rjyotisingh123
 
Exploratory Data Analysis
Exploratory Data Analysis
Umair Shafique
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
Line graph bar graph
Line graph bar graph
Ayesha Arshad
 
Line & Bar Graphs
Line & Bar Graphs
herbison
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
1. Introduction.pptx
1. Introduction.pptx
SungaleliYuen
 
visual representation with BOX PLOT,BAR PLOTS
visual representation with BOX PLOT,BAR PLOTS
anjanasharma77573
 
Domain and Range of a Function- Day3.pptx
Domain and Range of a Function- Day3.pptx
lorryswift847
 
Graphing Data
Graphing Data
shas595
 
M2M_250327_22434hjjik7_250411_183538.pdf
M2M_250327_22434hjjik7_250411_183538.pdf
HebaEng
 
Ad

More from CHANDAN KUMAR (13)

Raid technology
Raid technology
CHANDAN KUMAR
 
Pointers in c
Pointers in c
CHANDAN KUMAR
 
Sorting algorithms
Sorting algorithms
CHANDAN KUMAR
 
Searching in c language
Searching in c language
CHANDAN KUMAR
 
Greedy algorithm
Greedy algorithm
CHANDAN KUMAR
 
Divide and conquer algorithm
Divide and conquer algorithm
CHANDAN KUMAR
 
Arrays in c
Arrays in c
CHANDAN KUMAR
 
Loops in c programming
Loops in c programming
CHANDAN KUMAR
 
Linked List
Linked List
CHANDAN KUMAR
 
Stack and queue
Stack and queue
CHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview c programming
CHANDAN KUMAR
 
Decision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
CHANDAN KUMAR
 
Searching in c language
Searching in c language
CHANDAN KUMAR
 
Divide and conquer algorithm
Divide and conquer algorithm
CHANDAN KUMAR
 
Loops in c programming
Loops in c programming
CHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview c programming
CHANDAN KUMAR
 
Decision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
CHANDAN KUMAR
 
Ad

Recently uploaded (20)

WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
João Esperancinha
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
ravicivil
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Blood bank management system project report.pdf
Blood bank management system project report.pdf
Kamal Acharya
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Engineering Mechanics Introduction and its Application
Engineering Mechanics Introduction and its Application
Sakthivel M
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
grade 9 science q1 quiz.pptx science quiz
grade 9 science q1 quiz.pptx science quiz
norfapangolima
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
João Esperancinha
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
ravicivil
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Blood bank management system project report.pdf
Blood bank management system project report.pdf
Kamal Acharya
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Engineering Mechanics Introduction and its Application
Engineering Mechanics Introduction and its Application
Sakthivel M
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
grade 9 science q1 quiz.pptx science quiz
grade 9 science q1 quiz.pptx science quiz
norfapangolima
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 

Chart and graphs in R programming language

  • 1. Charts and Graphs- R Programming
  • 2. Introduction  Since we know that a huge amount of data is generated when it comes to interpreting any sector  To acquire significant insights, it is usually preferable to depict data through charts and graphs rather than scanning large Excel sheets.  The R programming language is mostly used to depict data graphically in software for statistics and data analytics.
  • 3.  The R programming language includes some simple and easy techniques for converting data into visually appealing features such as graphs and charts.  In R, charts and graphs are used to graphically depict the data.  R Programming language has numerous libraries to create charts and graphs.  There are numerous types of charts and graphs are present in R language such as pie chart, scatter graph, bar plot, box plot, mosaic plot, dot chart, coplot, histogram, etc.
  • 4. Pie Chart  A pie chart is a visual depiction of values as colored slices of a circle.  The slices are identified, and the graphic also shows the numbers that correlate to each slice.  The pie chart is made in R using the pie() function, which requires a vector input of positive values.  The extra options are used to customize labels, color, and title, among other things.
  • 5.  Syntax: pie(x, labels, radius, main, col, clockwise) vector Description radius of the circle Direction color palette Title
  • 6. Here,  x indicates a vector that contain numerical values.  labels is used to describe the slices.  radius indicates the radius of the circle of the pie chart. (value between −1 and +1).  The chart's title is indicated by the main.  The color palette is indicated by col.  The logical value clockwise indicates whether the slices are drawn clockwise or anticlockwise.
  • 7. Example-1 We can create a very simple pie-chart with the help of only two parameters such as the input vector and labels. # Firstly we Create data i.e. vector for the chart. x <- c(35, 60, 20, 40) # After that naming labels of slices labels <- c(“INDIA", "NEW YORK", “NEW DELHI", "MUMBAI") # Call pie() function to Plot the chart pie(x,labels)
  • 8.  After executing these commands R Console shows the given chart.
  • 9. Example- 2 #The below script will create a pie chart and save the pie chart in the current R working directory. x <- c(35, 60, 20, 40) labels <- c(“KANPUR", “BAREILLY", “NEW DELHI", "MUMBAI") # Call png() function to give the chart file name. png(file = "city.png") pie(x,labels) # To Save the file. dev.off()
  • 10. Example- 3  #We can expand the features of the pie chart by adding more parameters to the function. The below script shows it.  pie(x, labels, main="City Pie Chart")
  • 11. Example- 4  pie(x,labels, radius= -1, main="City Pie Chart")
  • 12. Example- 5  pie(x, labels, radius= 1, main="City Pie Chart", col="RED")  Note: For rainbow color pallet, Use rainbow function.
  • 13. 3D Pie Chart  We can also draw pie chart with 3 dimensions i.e. 3D using additional packages.  plotrix package has a function called pie3D() that is used for creating 3D pie chart.
  • 14. Example- 6 # Install Package Install.packages(“plotrix”) # Get the library. library(plotrix) # Create data for the graph. x <- c(35, 60, 20, 40) labels <- c(“KANPUR", “BAREILLY", “NEW DELHI", "MUMBAI") pie3D(x,labels = lbl,explode = 0.1, main = "Pie Chart of Countries ")
  • 15. Histograms  A histogram represents the frequencies of values of a variable bucketed into ranges.  Histogram is similar to bar chat but the difference is it groups the values into continuous ranges i.e. In a histogram, there are no gaps between the bars, unlike a bar graph.  Each bar in histogram represents the height of the number of values present in that range.
  • 16.  R creates histogram using hist() function.  This function takes a vector as an input and uses some more parameters to plot histograms.  We Use histograms when we have continuous measurements and want to understand the distribution of values and look for outliers.
  • 17.  Syntax: hist(v,main,xlab,xlim,ylim,breaks,col,border) vector Description description of x-axis width of each bar range of values on the y-axis. range of values on the x-axis color palette set border color
  • 18. Here  v indicates vector that contain numeric values.  Title of the chart is indicated by main  col parameter is used to set color of the bars.  To set border color of each bar, border parameter is used.  xlab is used to give description of x-axis.  xlim and ylim are used to specify the range of values on the x- axis and y-axis respectively.  breaks is used to mention the width of each bar.
  • 19. Example- 1  # Create histogram  # Create data for the graph. v <- c(7,11,19,7,40,12,22,31,44,55,43)  # Create the histogram. hist( v, xlab = "Weight", col = "yellow", border = "blue")
  • 20. Example- 2  The xlim and ylim parameters can be used to set the range of values allowed in the X and Y axes, respectively.  Breaks can be used to determine the width of each bar. v <- c(7,11,19,7,40,12,22,31,44,55,43) hist(v,xlab = "Weight",col = "green",border = "red",xlim = c(0,40), ylim = c(0,5), breaks = 5)
  • 21. Bar Charts  A bar chart depicts data as rectangular bars whose length is proportionate to the variable's value.  The function barplot() in R is used to make bar charts.  In a bar chart, R can create both vertical and horizontal bars.  Each of the bars in a bar chart can be colored differently.
  • 22.  Syntax: barplot(H,xlab,ylab,main, names.arg,col) vector label for x axis width of each bar label for y axis Title names appearing under each bar colors to the bars
  • 23. Here,  H indicates vector or matrix that contain numeric values.  xlab is the label for x axis.  ylab is the label for y axis.  main is the title of the bar chart.  names.arg is a vector of names appearing under each bar.  col is used to give colors to the bars in the graph.
  • 24. Example- 1  Create a simple bar chart  # Create the data for the bar chart  H <- c(9,15,23,13,22)  # Plot the bar chart  barplot(H)
  • 25. Example- 2 Create a simple bar chart using vector and names of each bar.  # Create the data for the bar chart H <- c(9,15,23,13,22) names <- c("March","April","May","June","July")  # Plot the bar chart barplot(H,names.arg = names)
  • 26. Example- 3  Create a bar chart using other parameters. H <- c(9,15,23,13,22) names <- c("March","April","May","June","July") barplot(H,names.arg=names,xlab="Months",ylab=“ Expenditure",col="yellow", main="Expenditure chart",border="black") Or We also use parameters in this sequence. barplot(H,xlab="Months",ylab="Expenditure",main="Expenditur e chart", names.arg = names, col= "blue")
  • 27. Line Graph  A line chart is a graph that connects a set of points by connecting them with line segments.  These points are sorted according to the value of one of their coordinates (typically the x-coordinate).  Line charts are commonly used to identify data trends.  The line graph was created using R's plot() function.
  • 28.  Syntax: plot(v, type, main, col, xlab, ylab) vector Title Draw points or lines label for x axis label for y axis colors to both the points and lines
  • 29. Here  The numeric values are stored in vector V  Type takes value "p" is used to draw only points, "l" is used to draw just lines, and "o" is used to draw both points and lines.  The x axis is labeled as xlab.  The y axis label is ylab.  The main is the chart's title.  The col is used to color both the points and the lines.
  • 30. Example- 1 We can create a simple line chart using two parameters the input vector and the type parameter as “o". v <- c(10,15,22,32) plot (v,type = “o”)
  • 31. Example - 2  Create using other parameters v <- c(10,15,11,17,28) plot (v, main = “Line Graph”, xlab = “Months”, ylab = “Expenditure”, type = “o”, col = “RED”)
  • 32. Example - 3  Using lines()function, More than one line can be drawn on the same chart v <- c(7,12,28,3,41) t <- c(14,7,6,19,3) plot(v,type = "o",col = “blue", xlab = "Months", ylab = “Expenditure", main = “Expenditure chart") lines(t, type = "o", col = “yellow")