SlideShare a Scribd company logo
R Programming
Sakthi Dasan Sekar
http://shakthydoss.com 1
Data visualization
R Graphics
R has quite powerful packages for data visualization.
R graphics can be viewed on screen and saved in various format like
pdf, png, jpg, wmf,ps and etc.
R packages provide full control to customize the graphic needs.
http://shakthydoss.com 2
Data visualization
Simple bar chart
A bar graph are plotted either horizontal or vertical bars to show comparisons
among categorical data.
Bars represent lengths or frequency or proportion in the categorical data.
barplot(x)
http://shakthydoss.com 3
Data visualization
Simple bar chart
counts <- table(mtcars$gear)
barplot(counts)
#horizontal bar chart
barplot(counts, horiz=TRUE)
http://shakthydoss.com 4
Data visualization
Simple bar chart
Adding title, legend and color.
counts <- table(mtcars$gear)
barplot(counts,
main="Simple Bar Plot",
xlab="Improvement",
ylab="Frequency",
legend=rownames(counts),
col=c("red", "yellow", "green")
)
http://shakthydoss.com 5
Data visualization
Stacked bar plot
# Stacked Bar Plot with Colors and Legend
counts <- table(mtcars$vs, mtcars$gear)
barplot(counts,
main="Car Distribution by Gears and VS",
xlab="Number of Gears",
col=c("grey","cornflowerblue"),
legend = rownames(counts))
http://shakthydoss.com 6
Data visualization
Grouped Bar Plot
# Grouped Bar Plot
counts <- table(mtcars$vs, mtcars$gear)
barplot(counts,
main="Car Distribution by Gears and VS",
xlab="Number of Gears",
col=c("grey","cornflowerblue"),
legend = rownames(counts), beside=TRUE)
http://shakthydoss.com 7
Data visualization
Simple Pie Chart
slices <- c(10, 12,4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")
pie( slices, labels = lbls, main="Simple Pie Chart")
http://shakthydoss.com 8
Data visualization
Simple Pie Chart
slices <- c(10, 12,4, 16, 8)
pct <- round(slices/sum(slices)*100)
lbls <- paste(c("US", "UK", "Australia",
"Germany", "France"), " ", pct, "%", sep="")
pie(slices, labels=lbls2,
col=rainbow(5),main="Pie Chart with Percentages")
http://shakthydoss.com 9
Data visualization
Simple pie chart – 3D
library(plotrix)
slices <- c(10, 12,4, 16, 8)
lbls <- paste(
c("US", "UK", "Australia", "Germany", "France"),
" ", pct, "%", sep="")
pie3D(slices, labels=lbls,explode=0.0,
main="3D Pie Chart")
http://shakthydoss.com 10
Data visualization
Histograms
Histograms display the distribution of a continuous variable.
It by dividing up the range of scores into bins on the x-axis and displaying the
frequency of scores in each bin on the y-axis.
You can create histograms with the function
hist(x)
http://shakthydoss.com 11
Data visualization
Histograms
mtcars$mpg #miles per gallon data
hist(mtcars$mpg)
# Colored Histogram with Different Number of Bins
hist(mtcars$mpg, breaks=8, col="lightgreen")
http://shakthydoss.com 12
Data visualization
Kernal density ploy
Histograms may not be the efficient way to view distribution always.
Kernal density plots are usually a much more effective way to view the
distribution of a variable.
plot(density(x))
http://shakthydoss.com 13
Data visualization
Kernal density plot
# kernel Density Plot
density_data <- density(mtcars$mpg)
plot(density_data)
# Filling density Plot with colour
density_data <- density(mtcars$mpg)
plot(density_data, main="Kernel Density of Miles Per Gallon")
polygon(density_data, col="skyblue", border="black")
http://shakthydoss.com 14
Data visualization
Line Chart
The line chart is represented by a series of data points connected with
a straight line. Line charts are most often used to visualize data that
changes over time.
lines(x, y,type=)
http://shakthydoss.com 15
Data visualization
Line Chart
weight <- c(2.5, 2.8, 3.2, 4.8, 5.1,
5.9, 6.8, 7.1, 7.8,8.1)
months <- c(0,1,2,3,4,5,6,7,8,9)
plot(months,
weight, type = "b",
main="Baby weight chart")
http://shakthydoss.com 16
Data visualization
Box plot
The box plot (a.k.a. whisker diagram) is another standardized way of
displaying the distribution of data based on the five number summary:
minimum, first quartile, median, third quartile, and maximum.
http://shakthydoss.com 17
Data visualization
Box Plot
vec <- c(3, 2, 5, 6, 4, 8, 1, 2, 3, 2, 4)
summary(vec)
boxplot(vec, varwidth = TRUE)
#varwidth=TRUE to make box plot proportionate to width
http://shakthydoss.com 18
Data visualization
Heat Map
A heat map is a two-dimensional representation of data in which values
are represented by colors. A simple heat map provides an immediate
visual summary of information. More elaborate heat maps allow the
viewer to understand complex data sets.
http://shakthydoss.com 19
Data visualization
Heat Map
data <- read.csv("HEATMAP.csv",header = TRUE)
#convert Data frame into matrix
data <- data.matrix(data[,-1])
heatmap(data,Rowv=NA, Colv=NA,
col = heat.colors(256), scale="column")
http://shakthydoss.com 20
Data visualization
Word cloud
A word cloud (a.ka tag cloud) can be an handy tool when you need to
highlight the most commonly cited words in a text using a quick
visualization.
R packages : wordcloud
http://shakthydoss.com 21
Data visualization
Word cloud
install.packages("wordcloud")
library("wordcloud")
data <- read.csv("TEXT.csv",header = TRUE)
head(data)
wordcloud(words = data$word,
freq = data$freq, min.freq = 2,
max.words=100, random.order=FALSE)
http://shakthydoss.com 22
Data visualization
Graphic outputs can be redirected to files.
pdf("filename.pdf") #PDF file
win.metafile("filename.wmf") #Windows metafile
png("filename.png") #PBG file
jpeg("filename.jpg") #JPEG file
bmp("filename.bmp") #BMP file
postscript("filename.ps") #PostScript file
http://shakthydoss.com 23
Data visualization
Graphic outputs can be redirected to files.
Example
jpeg("myplot.jpg")
counts <- table(mtcars$gear)
barplot(counts)
dev.off()
http://shakthydoss.com 24
Data visualization
Graphic outputs can be redirected to files.
Function dev.off( )
should be used to return the control back to terminal.
Another way saving graphics to file.
dev.copy(jpeg, filename="myplot.jpg");
counts <- table(mtcars$gear)
barplot(counts)
dev.off()
http://shakthydoss.com 25
Data visualization
Export graphs in RStudio
In Graphic panel of RStuido
Step1 : Select Plots tab Click Explore menu
and chose Save as Image.
Step 2: Save image window will open.
Step3 : Select image format and the
directory to save the file.
Step4 : Click save.
http://shakthydoss.com 26
Data visualization
Export graphs in RStudio
To Export as pdf
Step 1: Click Export Menu and
click save as PDF.
Step 2:Select the directory to
save the file.
Step3: Click Save.
http://shakthydoss.com 27
Data visualization
Knowledge Check
http://shakthydoss.com 28
Data visualization
____________ represent lengths or frequency or proportion in the
categorical data.
A. Line charts
B. Bot plot
C. Bar charts
D. Kernal Density plot
Answer C
http://shakthydoss.com 29
Data visualization
___________ displays the distribution of data based on the five
number summary: minimum, first quartile, median, third quartile, and
maximum.
A. Line charts
B. Bot plot
C. Bar charts
D. Kernal Density plot
Answer B
http://shakthydoss.com 30
Data visualization
Histograms display the distribution of a continuous variable.
A. TRUE
B. FALSE
Answer A
http://shakthydoss.com 31
Data visualization
Graphic outputs can be redirected to file using _____________
function.
A. save("filename.png")
B. write.table("filename.png")
C. write.file("filename.png")
D. png("filename.png")
Answer D
http://shakthydoss.com 32
Data visualization
___________ visualization can be used highlight the most commonly
cited words in a text.
A. Word Stemmer
B. Word cloud
C. Histograms
D. Line chats
Answer B
http://shakthydoss.com 33
Ad

Recommended

1 R Tutorial Introduction
1 R Tutorial Introduction
Sakthi Dasans
 
Data visualization using R
Data visualization using R
Ummiya Mohammedi
 
Introduction to Rstudio
Introduction to Rstudio
Olga Scrivner
 
Data visualization with R
Data visualization with R
Biswajeet Dasmajumdar
 
Introduction to R Graphics with ggplot2
Introduction to R Graphics with ggplot2
izahn
 
Data Visualization With R
Data Visualization With R
Rsquared Academy
 
Introduction to R Programming
Introduction to R Programming
izahn
 
Unit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
2 R Tutorial Programming
2 R Tutorial Programming
Sakthi Dasans
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
jwjablonski
 
Introduction to R programming
Introduction to R programming
Victor Ordu
 
R Programming: Importing Data In R
R Programming: Importing Data In R
Rsquared Academy
 
Using Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
 
Css color and background properties
Css color and background properties
Jesus Obenita Jr.
 
Introduction to HTML5 and CSS3 (revised)
Introduction to HTML5 and CSS3 (revised)
Joseph Lewis
 
A c program of Phonebook application
A c program of Phonebook application
svrohith 9
 
CSS
CSS
seedinteractive
 
State of the Word 2016
State of the Word 2016
photomatt
 
Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
Data Analysis and Visualization using Python
Data Analysis and Visualization using Python
Chariza Pladin
 
Artificial intelligence ||practical file||art integrated work activity||delh...
Artificial intelligence ||practical file||art integrated work activity||delh...
unknown brain
 
cpp input & output system basics
cpp input & output system basics
gourav kottawar
 
HTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts Basics
Sun Technlogies
 
Looking at how Scratch and Python compare
Looking at how Scratch and Python compare
Emily de la Pena
 
C Programming Project
C Programming Project
Vijayananda Mohire
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILE
Dipta Saha
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
Emotion detection from text using data mining and text mining
Emotion detection from text using data mining and text mining
Sakthi Dasans
 
DATA VISUALIZATION WITH R PACKAGES
DATA VISUALIZATION WITH R PACKAGES
Fatma ÇINAR
 

More Related Content

What's hot (20)

2 R Tutorial Programming
2 R Tutorial Programming
Sakthi Dasans
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
jwjablonski
 
Introduction to R programming
Introduction to R programming
Victor Ordu
 
R Programming: Importing Data In R
R Programming: Importing Data In R
Rsquared Academy
 
Using Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
 
Css color and background properties
Css color and background properties
Jesus Obenita Jr.
 
Introduction to HTML5 and CSS3 (revised)
Introduction to HTML5 and CSS3 (revised)
Joseph Lewis
 
A c program of Phonebook application
A c program of Phonebook application
svrohith 9
 
CSS
CSS
seedinteractive
 
State of the Word 2016
State of the Word 2016
photomatt
 
Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
Data Analysis and Visualization using Python
Data Analysis and Visualization using Python
Chariza Pladin
 
Artificial intelligence ||practical file||art integrated work activity||delh...
Artificial intelligence ||practical file||art integrated work activity||delh...
unknown brain
 
cpp input & output system basics
cpp input & output system basics
gourav kottawar
 
HTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts Basics
Sun Technlogies
 
Looking at how Scratch and Python compare
Looking at how Scratch and Python compare
Emily de la Pena
 
C Programming Project
C Programming Project
Vijayananda Mohire
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILE
Dipta Saha
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
2 R Tutorial Programming
2 R Tutorial Programming
Sakthi Dasans
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
jwjablonski
 
Introduction to R programming
Introduction to R programming
Victor Ordu
 
R Programming: Importing Data In R
R Programming: Importing Data In R
Rsquared Academy
 
Using Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
 
Css color and background properties
Css color and background properties
Jesus Obenita Jr.
 
Introduction to HTML5 and CSS3 (revised)
Introduction to HTML5 and CSS3 (revised)
Joseph Lewis
 
A c program of Phonebook application
A c program of Phonebook application
svrohith 9
 
State of the Word 2016
State of the Word 2016
photomatt
 
Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
Data Analysis and Visualization using Python
Data Analysis and Visualization using Python
Chariza Pladin
 
Artificial intelligence ||practical file||art integrated work activity||delh...
Artificial intelligence ||practical file||art integrated work activity||delh...
unknown brain
 
cpp input & output system basics
cpp input & output system basics
gourav kottawar
 
HTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts Basics
Sun Technlogies
 
Looking at how Scratch and Python compare
Looking at how Scratch and Python compare
Emily de la Pena
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILE
Dipta Saha
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 

Viewers also liked (6)

Emotion detection from text using data mining and text mining
Emotion detection from text using data mining and text mining
Sakthi Dasans
 
DATA VISUALIZATION WITH R PACKAGES
DATA VISUALIZATION WITH R PACKAGES
Fatma ÇINAR
 
Emotion Detection from Text
Emotion Detection from Text
IJERD Editor
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
Sakthi Dasans
 
Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013
Tanya Cashorali
 
Performance data visualization with r and tableau
Performance data visualization with r and tableau
Enkitec
 
Emotion detection from text using data mining and text mining
Emotion detection from text using data mining and text mining
Sakthi Dasans
 
DATA VISUALIZATION WITH R PACKAGES
DATA VISUALIZATION WITH R PACKAGES
Fatma ÇINAR
 
Emotion Detection from Text
Emotion Detection from Text
IJERD Editor
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
Sakthi Dasans
 
Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013
Tanya Cashorali
 
Performance data visualization with r and tableau
Performance data visualization with r and tableau
Enkitec
 
Ad

Similar to 5 R Tutorial Data Visualization (20)

Data visualization
Data visualization
Baijayanti Chakraborty
 
Lecture 6 Data Visualisation.pptxsfsfsfsfsdfs
Lecture 6 Data Visualisation.pptxsfsfsfsfsdfs
lewwai22tw
 
Data Visualization in R (Graph, Trend, etc)
Data Visualization in R (Graph, Trend, etc)
Rudyansyah -
 
17TH October 2023 DOE SRM University.pptx
17TH October 2023 DOE SRM University.pptx
Vikash431966
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in Heaven
Edureka!
 
Data Visualization by David Kretch
Data Visualization by David Kretch
Summit Consulting, LLC
 
M4_DAR_part1. module part 4 analystics with r
M4_DAR_part1. module part 4 analystics with r
LalithauLali
 
Science Online 2013: Data Visualization Using R
Science Online 2013: Data Visualization Using R
William Gunn
 
Exploratory data analysis using r
Exploratory data analysis using r
Tahera Shaikh
 
Data visualization
Data visualization
Vivian S. Zhang
 
Exploratory Data Analysis
Exploratory Data Analysis
Umair Shafique
 
Overview data analyis and visualisation tools 2020
Overview data analyis and visualisation tools 2020
Marié Roux
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in Heaven
Edureka!
 
Data visualization with R and ggplot2.docx
Data visualization with R and ggplot2.docx
kassaye4
 
Introduction to Data Visualization, Importance and types
Introduction to Data Visualization, Importance and types
grsssyw24
 
R visualization: ggplot2, googlevis, plotly, igraph Overview
R visualization: ggplot2, googlevis, plotly, igraph Overview
Olga Scrivner
 
R programming for data science
R programming for data science
Sovello Hildebrand
 
Chart and graphs in R programming language
Chart and graphs in R programming language
CHANDAN KUMAR
 
Overview of tools for data analysis and visualisation (2021)
Overview of tools for data analysis and visualisation (2021)
Marié Roux
 
Introduction to Data Visualization for Agriculture and Allied Sciences using ...
Introduction to Data Visualization for Agriculture and Allied Sciences using ...
Shubham Shah
 
Lecture 6 Data Visualisation.pptxsfsfsfsfsdfs
Lecture 6 Data Visualisation.pptxsfsfsfsfsdfs
lewwai22tw
 
Data Visualization in R (Graph, Trend, etc)
Data Visualization in R (Graph, Trend, etc)
Rudyansyah -
 
17TH October 2023 DOE SRM University.pptx
17TH October 2023 DOE SRM University.pptx
Vikash431966
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in Heaven
Edureka!
 
M4_DAR_part1. module part 4 analystics with r
M4_DAR_part1. module part 4 analystics with r
LalithauLali
 
Science Online 2013: Data Visualization Using R
Science Online 2013: Data Visualization Using R
William Gunn
 
Exploratory data analysis using r
Exploratory data analysis using r
Tahera Shaikh
 
Exploratory Data Analysis
Exploratory Data Analysis
Umair Shafique
 
Overview data analyis and visualisation tools 2020
Overview data analyis and visualisation tools 2020
Marié Roux
 
R and Visualization: A match made in Heaven
R and Visualization: A match made in Heaven
Edureka!
 
Data visualization with R and ggplot2.docx
Data visualization with R and ggplot2.docx
kassaye4
 
Introduction to Data Visualization, Importance and types
Introduction to Data Visualization, Importance and types
grsssyw24
 
R visualization: ggplot2, googlevis, plotly, igraph Overview
R visualization: ggplot2, googlevis, plotly, igraph Overview
Olga Scrivner
 
R programming for data science
R programming for data science
Sovello Hildebrand
 
Chart and graphs in R programming language
Chart and graphs in R programming language
CHANDAN KUMAR
 
Overview of tools for data analysis and visualisation (2021)
Overview of tools for data analysis and visualisation (2021)
Marié Roux
 
Introduction to Data Visualization for Agriculture and Allied Sciences using ...
Introduction to Data Visualization for Agriculture and Allied Sciences using ...
Shubham Shah
 
Ad

Recently uploaded (20)

presentation4.pdf Intro to mcmc methodss
presentation4.pdf Intro to mcmc methodss
SergeyTsygankov6
 
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Prasenjit Debnath
 
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
Indigo_Airlines_Strategy_Presentation.pptx
Indigo_Airlines_Strategy_Presentation.pptx
mukeshpurohit991
 
25 items quiz for practical research 1 in grade 11
25 items quiz for practical research 1 in grade 11
leamaydayaganon81
 
Predicting Titanic Survival Presentation
Predicting Titanic Survival Presentation
praxyfarhana
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
Taqyea
 
Informatics Market Insights AI Workforce.pdf
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
Flextronics Employee Safety Data-Project-2.pptx
Flextronics Employee Safety Data-Project-2.pptx
kilarihemadri
 
PPT2 W1L2.pptx.........................................
PPT2 W1L2.pptx.........................................
palicteronalyn26
 
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
 
Measurecamp Copenhagen - Consent Context
Measurecamp Copenhagen - Consent Context
Human37
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
RESEARCH-FINAL-GROUP-3, about the final .pptx
RESEARCH-FINAL-GROUP-3, about the final .pptx
gwapokoha1
 
Camuflaje Tipos Características Militar 2025.ppt
Camuflaje Tipos Características Militar 2025.ppt
e58650738
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
presentation4.pdf Intro to mcmc methodss
presentation4.pdf Intro to mcmc methodss
SergeyTsygankov6
 
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Prasenjit Debnath
 
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
Indigo_Airlines_Strategy_Presentation.pptx
Indigo_Airlines_Strategy_Presentation.pptx
mukeshpurohit991
 
25 items quiz for practical research 1 in grade 11
25 items quiz for practical research 1 in grade 11
leamaydayaganon81
 
Predicting Titanic Survival Presentation
Predicting Titanic Survival Presentation
praxyfarhana
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
Taqyea
 
Informatics Market Insights AI Workforce.pdf
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
Flextronics Employee Safety Data-Project-2.pptx
Flextronics Employee Safety Data-Project-2.pptx
kilarihemadri
 
PPT2 W1L2.pptx.........................................
PPT2 W1L2.pptx.........................................
palicteronalyn26
 
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
 
Measurecamp Copenhagen - Consent Context
Measurecamp Copenhagen - Consent Context
Human37
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
RESEARCH-FINAL-GROUP-3, about the final .pptx
RESEARCH-FINAL-GROUP-3, about the final .pptx
gwapokoha1
 
Camuflaje Tipos Características Militar 2025.ppt
Camuflaje Tipos Características Militar 2025.ppt
e58650738
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 

5 R Tutorial Data Visualization

  • 1. R Programming Sakthi Dasan Sekar http://shakthydoss.com 1
  • 2. Data visualization R Graphics R has quite powerful packages for data visualization. R graphics can be viewed on screen and saved in various format like pdf, png, jpg, wmf,ps and etc. R packages provide full control to customize the graphic needs. http://shakthydoss.com 2
  • 3. Data visualization Simple bar chart A bar graph are plotted either horizontal or vertical bars to show comparisons among categorical data. Bars represent lengths or frequency or proportion in the categorical data. barplot(x) http://shakthydoss.com 3
  • 4. Data visualization Simple bar chart counts <- table(mtcars$gear) barplot(counts) #horizontal bar chart barplot(counts, horiz=TRUE) http://shakthydoss.com 4
  • 5. Data visualization Simple bar chart Adding title, legend and color. counts <- table(mtcars$gear) barplot(counts, main="Simple Bar Plot", xlab="Improvement", ylab="Frequency", legend=rownames(counts), col=c("red", "yellow", "green") ) http://shakthydoss.com 5
  • 6. Data visualization Stacked bar plot # Stacked Bar Plot with Colors and Legend counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS", xlab="Number of Gears", col=c("grey","cornflowerblue"), legend = rownames(counts)) http://shakthydoss.com 6
  • 7. Data visualization Grouped Bar Plot # Grouped Bar Plot counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS", xlab="Number of Gears", col=c("grey","cornflowerblue"), legend = rownames(counts), beside=TRUE) http://shakthydoss.com 7
  • 8. Data visualization Simple Pie Chart slices <- c(10, 12,4, 16, 8) lbls <- c("US", "UK", "Australia", "Germany", "France") pie( slices, labels = lbls, main="Simple Pie Chart") http://shakthydoss.com 8
  • 9. Data visualization Simple Pie Chart slices <- c(10, 12,4, 16, 8) pct <- round(slices/sum(slices)*100) lbls <- paste(c("US", "UK", "Australia", "Germany", "France"), " ", pct, "%", sep="") pie(slices, labels=lbls2, col=rainbow(5),main="Pie Chart with Percentages") http://shakthydoss.com 9
  • 10. Data visualization Simple pie chart – 3D library(plotrix) slices <- c(10, 12,4, 16, 8) lbls <- paste( c("US", "UK", "Australia", "Germany", "France"), " ", pct, "%", sep="") pie3D(slices, labels=lbls,explode=0.0, main="3D Pie Chart") http://shakthydoss.com 10
  • 11. Data visualization Histograms Histograms display the distribution of a continuous variable. It by dividing up the range of scores into bins on the x-axis and displaying the frequency of scores in each bin on the y-axis. You can create histograms with the function hist(x) http://shakthydoss.com 11
  • 12. Data visualization Histograms mtcars$mpg #miles per gallon data hist(mtcars$mpg) # Colored Histogram with Different Number of Bins hist(mtcars$mpg, breaks=8, col="lightgreen") http://shakthydoss.com 12
  • 13. Data visualization Kernal density ploy Histograms may not be the efficient way to view distribution always. Kernal density plots are usually a much more effective way to view the distribution of a variable. plot(density(x)) http://shakthydoss.com 13
  • 14. Data visualization Kernal density plot # kernel Density Plot density_data <- density(mtcars$mpg) plot(density_data) # Filling density Plot with colour density_data <- density(mtcars$mpg) plot(density_data, main="Kernel Density of Miles Per Gallon") polygon(density_data, col="skyblue", border="black") http://shakthydoss.com 14
  • 15. Data visualization Line Chart The line chart is represented by a series of data points connected with a straight line. Line charts are most often used to visualize data that changes over time. lines(x, y,type=) http://shakthydoss.com 15
  • 16. Data visualization Line Chart weight <- c(2.5, 2.8, 3.2, 4.8, 5.1, 5.9, 6.8, 7.1, 7.8,8.1) months <- c(0,1,2,3,4,5,6,7,8,9) plot(months, weight, type = "b", main="Baby weight chart") http://shakthydoss.com 16
  • 17. Data visualization Box plot The box plot (a.k.a. whisker diagram) is another standardized way of displaying the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum. http://shakthydoss.com 17
  • 18. Data visualization Box Plot vec <- c(3, 2, 5, 6, 4, 8, 1, 2, 3, 2, 4) summary(vec) boxplot(vec, varwidth = TRUE) #varwidth=TRUE to make box plot proportionate to width http://shakthydoss.com 18
  • 19. Data visualization Heat Map A heat map is a two-dimensional representation of data in which values are represented by colors. A simple heat map provides an immediate visual summary of information. More elaborate heat maps allow the viewer to understand complex data sets. http://shakthydoss.com 19
  • 20. Data visualization Heat Map data <- read.csv("HEATMAP.csv",header = TRUE) #convert Data frame into matrix data <- data.matrix(data[,-1]) heatmap(data,Rowv=NA, Colv=NA, col = heat.colors(256), scale="column") http://shakthydoss.com 20
  • 21. Data visualization Word cloud A word cloud (a.ka tag cloud) can be an handy tool when you need to highlight the most commonly cited words in a text using a quick visualization. R packages : wordcloud http://shakthydoss.com 21
  • 22. Data visualization Word cloud install.packages("wordcloud") library("wordcloud") data <- read.csv("TEXT.csv",header = TRUE) head(data) wordcloud(words = data$word, freq = data$freq, min.freq = 2, max.words=100, random.order=FALSE) http://shakthydoss.com 22
  • 23. Data visualization Graphic outputs can be redirected to files. pdf("filename.pdf") #PDF file win.metafile("filename.wmf") #Windows metafile png("filename.png") #PBG file jpeg("filename.jpg") #JPEG file bmp("filename.bmp") #BMP file postscript("filename.ps") #PostScript file http://shakthydoss.com 23
  • 24. Data visualization Graphic outputs can be redirected to files. Example jpeg("myplot.jpg") counts <- table(mtcars$gear) barplot(counts) dev.off() http://shakthydoss.com 24
  • 25. Data visualization Graphic outputs can be redirected to files. Function dev.off( ) should be used to return the control back to terminal. Another way saving graphics to file. dev.copy(jpeg, filename="myplot.jpg"); counts <- table(mtcars$gear) barplot(counts) dev.off() http://shakthydoss.com 25
  • 26. Data visualization Export graphs in RStudio In Graphic panel of RStuido Step1 : Select Plots tab Click Explore menu and chose Save as Image. Step 2: Save image window will open. Step3 : Select image format and the directory to save the file. Step4 : Click save. http://shakthydoss.com 26
  • 27. Data visualization Export graphs in RStudio To Export as pdf Step 1: Click Export Menu and click save as PDF. Step 2:Select the directory to save the file. Step3: Click Save. http://shakthydoss.com 27
  • 29. Data visualization ____________ represent lengths or frequency or proportion in the categorical data. A. Line charts B. Bot plot C. Bar charts D. Kernal Density plot Answer C http://shakthydoss.com 29
  • 30. Data visualization ___________ displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum. A. Line charts B. Bot plot C. Bar charts D. Kernal Density plot Answer B http://shakthydoss.com 30
  • 31. Data visualization Histograms display the distribution of a continuous variable. A. TRUE B. FALSE Answer A http://shakthydoss.com 31
  • 32. Data visualization Graphic outputs can be redirected to file using _____________ function. A. save("filename.png") B. write.table("filename.png") C. write.file("filename.png") D. png("filename.png") Answer D http://shakthydoss.com 32
  • 33. Data visualization ___________ visualization can be used highlight the most commonly cited words in a text. A. Word Stemmer B. Word cloud C. Histograms D. Line chats Answer B http://shakthydoss.com 33