SlideShare a Scribd company logo
1 of 33
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

Descriptive Statistics with R
Descriptive Statistics with RDescriptive Statistics with R
Descriptive Statistics with R
Kazuki Yoshida
 

What's hot (20)

Data Types and Structures in R
Data Types and Structures in RData Types and Structures in R
Data Types and Structures in R
 
Data Visualization With R
Data Visualization With RData Visualization With R
Data Visualization With R
 
Descriptive Statistics with R
Descriptive Statistics with RDescriptive Statistics with R
Descriptive Statistics with R
 
Introduction to R and R Studio
Introduction to R and R StudioIntroduction to R and R Studio
Introduction to R and R Studio
 
Developing R Graphical User Interfaces
Developing R Graphical User InterfacesDeveloping R Graphical User Interfaces
Developing R Graphical User Interfaces
 
R programming slides
R  programming slidesR  programming slides
R programming slides
 
Regression analysis in R
Regression analysis in RRegression analysis in R
Regression analysis in R
 
R data types
R data typesR data types
R data types
 
Association rule mining
Association rule miningAssociation rule mining
Association rule mining
 
Data tidying with tidyr meetup
Data tidying with tidyr  meetupData tidying with tidyr  meetup
Data tidying with tidyr meetup
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R Packages
 
Introduction to R Graphics with ggplot2
Introduction to R Graphics with ggplot2Introduction to R Graphics with ggplot2
Introduction to R Graphics with ggplot2
 
An Introduction To Weka
An Introduction To WekaAn Introduction To Weka
An Introduction To Weka
 
Regression ppt
Regression pptRegression ppt
Regression ppt
 
An Introduction to Data Mining with R
An Introduction to Data Mining with RAn Introduction to Data Mining with R
An Introduction to Data Mining with R
 
R studio
R studio R studio
R studio
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
R data types
R   data typesR   data types
R data types
 

Similar to Chart and graphs in R programming language

Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphics
etyca
 
pie chart ppt.pdf ppt on pie chart. Veri formal
pie chart ppt.pdf ppt on pie chart. Veri formalpie chart ppt.pdf ppt on pie chart. Veri formal
pie chart ppt.pdf ppt on pie chart. Veri formal
rjyotisingh123
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
Line & Bar Graphs
Line & Bar GraphsLine & Bar Graphs
Line & Bar Graphs
herbison
 
Graphing Data
Graphing DataGraphing Data
Graphing Data
shas595
 

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

Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using r
 
R graphics
R graphicsR graphics
R graphics
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphics
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
pie chart ppt.pdf ppt on pie chart. Veri formal
pie chart ppt.pdf ppt on pie chart. Veri formalpie chart ppt.pdf ppt on pie chart. Veri formal
pie chart ppt.pdf ppt on pie chart. Veri formal
 
Exploratory Data Analysis
Exploratory Data AnalysisExploratory Data Analysis
Exploratory Data Analysis
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
R training5
R training5R training5
R training5
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Line graph bar graph
Line graph bar graphLine graph bar graph
Line graph bar graph
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
 
Line & Bar Graphs
Line & Bar GraphsLine & Bar Graphs
Line & Bar Graphs
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar PlotsR Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar Plots
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptx
 
Graphing Data
Graphing DataGraphing Data
Graphing Data
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
R scatter plots
R scatter plotsR scatter plots
R scatter plots
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
02 linear algebra
02 linear algebra02 linear algebra
02 linear algebra
 

More from CHANDAN KUMAR

More from CHANDAN KUMAR (13)

Raid technology
Raid technologyRaid technology
Raid technology
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Linked List
Linked ListLinked List
Linked List
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
 

Recently uploaded

scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

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")