100% found this document useful (1 vote)
129 views

Pie and Bar Chart: Slide 1

This document discusses different types of charts used to visualize data, including pie charts, bar charts, and box plots. It provides examples of simple and more advanced pie charts, bar charts, and box plots using the built-in R datasets iris and mtcars to illustrate different charting techniques. Pie charts show proportional data as slices of a circle, bar charts allow comparisons between categories through vertical or horizontal bars, and box plots display the distribution of data through minimum, quartiles, and maximum values.

Uploaded by

Aparna Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
129 views

Pie and Bar Chart: Slide 1

This document discusses different types of charts used to visualize data, including pie charts, bar charts, and box plots. It provides examples of simple and more advanced pie charts, bar charts, and box plots using the built-in R datasets iris and mtcars to illustrate different charting techniques. Pie charts show proportional data as slices of a circle, bar charts allow comparisons between categories through vertical or horizontal bars, and box plots display the distribution of data through minimum, quartiles, and maximum values.

Uploaded by

Aparna Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Pie and Bar chart

Slide 1:
A pie chart (or a circle chart) is a circular statistical graphic, which is divided into slices to
illustrate numerical proportion. In a pie chart, the arc length of each slice (and consequently
its central angle and area), is proportional to the quantity it represents.
It represents data visually as a fractional part of a whole, which can be an effective
communication tool for the even uninformed audience. It enables the audience to see a
data comparison at a glance to make an immediate analysis or to understand information
quickly.
Slide 2
Simple Pie chart
slices=c(283, 112,83, 50, 26) # Deaths due COVID 19 as on 23rd April-2020
lbls=c("Maharashtra=283", "Gujarat=112", "MP=83", "Delhi=50", "Telangana=26")
pie(slices, labels = lbls, main="Pie Chart of deaths due to Covid till 23rd April ")

#pie chart with annotated percentages


slices=c(283, 112,83, 50, 26) # Deaths due COVID 19 as on 23rd April-2020
lbls=c("Maharashtra", "Gujarat", "MP", "Delhi", "Telangana")
pct=round(slices/sum(slices)*100)
lbls=paste(lbls, pct) # add percents to labels
lbls=paste(lbls,"%",sep="") # ad % to labels
pie(slices,labels = lbls, col=rainbow(length(lbls)),
main="Deaths due to COVID 19 as on 23rd April")
# 3D pie chart
# 3D Exploded Pie Chart
# Install package plotrix
library(plotrix)
slices=c(283, 112,83, 50, 26)
lbls=c("Maharashtra=283", "Gujarat=112", "MP=83", "Delhi=50", "Telangana=26")
pie3D(slices,labels=lbls,explode=0.1,
main="Deaths due to COVID 19 as on 23rd April ")

Pie Chart from data frame with Appended Sample Sizes


mytable <- table(iris$Species)
lbls <- paste(names(mytable), "\n", mytable, sep="")
pie(mytable, labels = lbls,
main="Pie Chart of Species\n (with sample sizes)")
Slide 3:
• A bar graph refers to a chart that makes use of bars to show the various
comparisons between categories of data. The bars can be either vertical or
horizontal. Bar graphs with vertical bars are also known as vertical bar graphs.
• The characteristics that make a good bar graph are as follows:
• Easy comparisons between different variables
• Clarity in displaying trends in data
• Easy determination in the value of a variable
Slide 4:
Bar Charts
#Simple bar chart
counts=table(mtcars$gear)
barplot(counts, main="Car Distribution",
xlab="Number of Gears")

# Simple Horizontal Bar Plot with Added Labels


counts=table(mtcars$gear)
barplot(counts, main="Car Distribution", horiz=TRUE,
names.arg=c("3 Gears", "4 Gears", "5 Gears"))

# Stacked Bar Plot with Colours and Legend


counts=table(mtcars$vs, mtcars$gear)
barplot(counts, main="Car Distribution by Gears and VS",
xlab="Number of Gears", col=c("darkblue","red"),
legend = rownames(counts))

# Grouped Bar Plot


counts=table(mtcars$vs, mtcars$gear)
barplot(counts, main="Car Distribution by Gears and VS",
xlab="Number of Gears", col=c("darkblue","red"),
legend = rownames(counts), beside=TRUE)
Slide 5: Box Plot
• The box plot (box and whisker diagram) is a standardized way of displaying the
distribution of data based on the five number summary: minimum, first quartile,
median, third quartile, and maximum.
# Boxplot of MPG by Car Cylinders
boxplot(mpg~cyl,data=mtcars, main="Car Milage Data",
xlab="Number of Cylinders", ylab="Miles Per Gallon")

You might also like