Chapter 4 Data Visualization
Chapter 4 Data Visualization
Output:
Qualitative Data
Instructions: Using BMI.sav, tabulate the count of
students according to each program enrolled
Output:
Qualitative Data
Instructions: Using BMI.sav, display a pie chart of
program
Output:
Qualitative Data
Instructions: Using BMI.sav, display a pie chart of
program with percentage
Output:
Qualitative Data
Exercises
1) Using IRIS dataset in R. Perform an R command to create a Pie chart with legends as
shown in the Figure.
2) Create a 3D pie chart as shown in the Figure. The pie chart should have a legend.
Species of Plants
33%
33%
33%
Qualitative Data
Instructions: Using BMI.sav, display a bar chart of
gender of students
#use barplot(freq.tab,xlab=,ylab=,main=)
Bar chart freq1=table(gender);freq1
barplot(freq1) #basic barplot
#Horizontal mode
barplot(freq1,horiz=TRUE)
Output:
Challenge:
Using the same data, create a bar chart
of program enrolled by students
Qualitative Data
Instructions: Using BMI.sav, display a stacked bar
chart of program enrolled according to gender of
students
Output:
Qualitative Data
Instructions: Using BMI.sav, display a clustered bar
chart of program enrolled according to gender of
students
Output:
Quantitative Data
Instructions: Using road dataset available in MASS
package, create a stem and leaf plot for temperature
(temp) variable
library(MASS)
dat4=roadstr(road)
Stem and Leaf Plot attach(road)
stem(temp,scale=0.5)
Output:
Quantitative Data
Instructions: Using BMI.sav, create a box and whisker
plot for variable height of students.
#Vertical box plot
boxplot(height)#basic function
Box and Whisker
Plot #horizontal box plot
boxplot(height,horizontal=T)
Output:
Challenge:
Using the same data, create a box plot
for variable weight of students
Quantitative Data
Instructions: Using BMI.sav, create a box and whisker plot
for variable height of students according to gender.
#Vertical box plot
boxplot(height~gender)#basic function
Box and Whisker
Plot #horizontal box plot
boxplot(height~gender,horizontal=T)
Output:
Challenge:
Using the same data, create a box plot
for variable weight of students according
to gender
Quantitative Data
Instructions: Using BMI.sav, create a histogram for
variable height of students
#Using hist(var)
Histogram hist(height)#basic function
Output:
Challenge:
Using the same data, create a histogram
for variable weight of students
Quantitative Data
Instructions: Using BMI.sav, display a stacked bar
chart of program enrolled according to gender of
students
hist(height,prob=T)
Histogram +
curve(dnorm(x,mean=mean(height),sd=sd(height)),
Normal Curve add=T,col="red",lwd=2,lty=1)
Output:
Challenge:
Using the same data, create a histogram
with normal curve for variable weight of
students
Quantitative Data
Instructions: Using BMI.sav, create a normal density
plot with normal curve height of students
plot(density(height))
curve(dnorm(x,mean=mean(height),sd=sd(height)),
Normal
add=T,col="red",lwd=2,lty=2)
Distribution Plot
Output:
Challenge:
Using the same data, create a normal
density plot with normal curve for
variable weight of students
Quantitative Data
Instructions: Using Ozone.csv, create a scatter plot
to observe the relationship between temperature and
wind speed.
Output:
Challenge:
Based on the figure, what can you
conclude on the relationship?
#https://r-lang.com/pch-in-
r/#:~:text=The%20pch%20stands%20for%20plot,point%20symbols%20(or%20shapes).
Quantitative Data
Instructions: Using Ozone.csv, create a normal q-q
plot to determine the distribution of the wind speed.
#Using qqnorm(var)
qqnorm(wind)
Normal Q-Q Plot qqline(wind)#adding the straight line
Output:
Challenge:
Based on the figure, what can you
conclude on the distribution of widn
speed?
Quantitative Data
Instructions: Using Ozone.csv, create an ogive of wind speed.
plot(ecdf(wind),col.hor="white",main="Cummulative frequency
distribution", xlab="Wind Speed", ylab="standard normal
Ogive deviate")
range1<-seq(0,20)
distr<-pnorm(range1,mean=mean(wind), sd=sd(wind))
lines(range1,distr, col="red", lwd=2)
Output:
Quantitative Data
ADDING TEXT LABEL IN PLOT
x1=c(124,118,130,127,103,141,114)
x2=c(75,80,95,77,68,105,84)
plot(x1,x2,xlab="systolic",ylab="diastolic",xlim=c(90,150),ylim=c(60,110),
main="Arterial pressure measurement")
text(x1,x2,c("A","C","B","D","E","F","G"),pos=4)
axis(side=1,col="gray",tck=1,lty="dotted")#add grid x-axis
axis(side=2,col="gray",tck=1,lty="dotted")#add grid y-axis
Output:
References
Arguments Description
lty = Line type
cex = Text size
col = Color
pch = Plot type
lwd = Line width
type = Graph type
#https://r-lang.com/pch-in-
r/#:~:text=The%20pch%20stands%
20for%20plot,point%20symbols%2
0(or%20shapes).