SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data framekrishna singh
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structurestudent
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in PythonDevashish Kumar
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbmsshekhar1991
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in pythonhydpy
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructurerajshreemuthiah
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
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, Factorskrishna singh
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 

La actualidad más candente (20)

Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Arrays
ArraysArrays
Arrays
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
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
 
Vector in R
Vector in RVector in R
Vector in R
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
 

Similar a Chart and graphs in R programming language

Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using rTahera Shaikh
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphicsetyca
 
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
 
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 formalrjyotisingh123
 
Exploratory Data Analysis
Exploratory Data AnalysisExploratory Data Analysis
Exploratory Data AnalysisUmair Shafique
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
Line graph bar graph
Line graph bar graphLine graph bar graph
Line graph bar graphAyesha Arshad
 
Line & Bar Graphs
Line & Bar GraphsLine & Bar Graphs
Line & Bar Graphsherbison
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar PlotsR Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar PlotsRsquared Academy
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptxSungaleliYuen
 
Graphing Data
Graphing DataGraphing Data
Graphing Datashas595
 
R scatter plots
R scatter plotsR scatter plots
R scatter plotsAbhik Seal
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lispLISP Content
 

Similar a 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
 

Más de CHANDAN KUMAR

Searching in c language
Searching in c languageSearching in c language
Searching in c languageCHANDAN KUMAR
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithmCHANDAN KUMAR
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programmingCHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programmingCHANDAN KUMAR
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statementCHANDAN KUMAR
 
"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 "CHANDAN KUMAR
 

Más de 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 "
 

Último

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 

Último (20)

DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 

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