Data Visualization Using R
Data Visualization Using R
Commands :
summary(mtcars$disp)
summary(mtcars$hp)
head(mtcars)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
View(mtcars)
plot(mtcars$mpg)
---------------------------------------------------------------------------------------------------------
class(mtcars$cyl)
mtcars$cylfact=as.factor(mtcars$cyl)
class(mtcars$cylfact)
mtcars$cylfact
plot(mtcars$cylfact)
---------------------------------------------------------------------------------------------------
plot(mtcars$disp, mtcars$mpg)
---------------------------------------------------------------------------------------------------
mtcars$amfact <- as.factor(mtcars$am)
mtcars$cylfact <- as.factor(mtcars$cyl)
plot(mtcars$amfact, mtcars$cylfact)
---------------------------------------------------------------------------------------------------
mtcars$cylfact <- as.factor(mtcars$cyl)
plot(mtcars$cylfact,mtcars$mpg)
---------------------------------------------------------------------------------------------------
plot(mtcars$disp, mtcars$mp,main="Displacement Vs MPG")
---------------------------------------------------------------------------------------------------
plot(mtcars$disp, mtcars$mp,main="Displacement Vs
MPG",sub=" Subtitle Displacement VS MPG")
---------------------------------------------------------------------------------------------------
plot(mtcars$disp, mtcars$mp,main="Displacement Vs
MPG",sub=" Subtitle Displacement VS
MPG",xlab="Displacement",ylab="MPG")
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
title() Function
plot(mtcars$disp, mtcars$mp,main="Displacement Vs
MPG",sub=" Subtitle Displacement VS
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
MPG",xlab="Displacement",ylab="MPG",xlim=c(0,600),ylim=c(0,50))
---------------------------------------------------------------------------------------------------
plot(mtcars$disp, mtcars$mp)
title(main="Displacement Vs
MPG",sub=" Subtitle
Displacement VS
MPG",xlab="Displacement",ylab="MPG",xlim=c(0,600),ylim=c(0,50))
---------------------------------------------------------------------------------------------------
Colours
plot(mtcars$disp, mtcars$mp,col="red",main="Main
Title",col.main="blue",sub="Subtitle",col.sub="green",xlab="Displacement",ylab="MPG",co
l.lab="red",col.axis=rgb(0,1,1),fg=rgb(1,1,0))
---------------------------------------------------------------------------------------------------
Font
1 Plain
2 Bold
3 Italic
4 Bold Italic
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
5 Symbol
---------------------------------------------------------------------------------------------------
plot(mtcars$disp,mtcars$mpg,font.axis=2,xlab="Displacement",ylab="MPG",font.lab=3)
plot(mtcars$disp,mtcars$mpg,font.axis=2,xlab="Displacement",ylab="MPG",font.lab=3,
main="Main Title",cex.main=2,sub="Subtitle",cex.sub=1.5,cex.lab=1.25,font.lab=2)
---------------------------------------------------------------------------------------------------
TEXT ANNOTATIONS
Text and Margin Text
text()
For adding text inside the plot
text( x,y,”Text String”)
mtext()
For adding next on margins
The margin where text need to be placed is specified by
side ( 1=Bottom, 2=Left, 3=Top, 4=Right)
Distance from margin is specified by line, default is 0
Positive value puts away from margin outside
Negative value puts away from margin inside
Horizontal alignment is done by adj ( 0 = left aligned , 1= right aligned)
Program
plot(mtcars$disp,mtcars$mpg,font.axis=2,xlab="Displacement",ylab="MPG",font.lab=3,mai
n="MainTitle", cex.main=2,sub="Subtitle",cex.sub=1.5,cex.lab=1.25,font.lab=2)
text(350,20,"This is sample text",col="red",font=2,family="mono")
text(250,25,"This is sample text",col="green",font=2,family="serif",cex=1.5)
mtext("Margin text",side=1,line=0,adj=1)
mtext("Margin text",side=3,line=3,adj=0)
mtext("Margin text", side=4,line=-3,adj=0)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
---------------------------------------------------------------------------------------------------
layout
The objective is to combine multiple graphs in a single frame
par()
Graphical parameters using mfcol and mfrow
layout()
More flexible than par()
Enables to height and widths of rows and columns
matrix specified the location of plot
widths = width of columns
heights = Height of rows
Programme
1.
nit=par(no.readonly = TRUE)
par(mfrow=c(2,2))
plot(mtcars$mpg)
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$disp)
boxplot(mtcars$mpg)
---------------------------------------------------------------------------------------------------
2.
layout(matrix(c(1,2,3,4),nrow=2,byrow=TRUE))
plot(mtcars$mpg)
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$disp)
boxplot(mtcars$mpg)
---------------------------------------------------------------------------------------------------
3
layout(matrix(c(1,2,3,4),nrow=2,byrow=FALSE))
plot(mtcars$mpg)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$disp)
boxplot(mtcars$mpg)
---------------------------------------------------------------------------------------------------
4
layout(matrix(c(1,2,3,3),nrow=2,byrow=FALSE))
plot(mtcars$mpg)
boxplot(mtcars$mpg)
plot(mtcars$disp)
---------------------------------------------------------------------------------------------------
Managing Width
layout(matrix(c(1,2,3,4,5,6),nrow=2,byrow=TRUE),width=c(1,2,1))
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$disp,mtcars$mpg)
plot(mtcars$disp,mtcars$mpg) Graph Description Formula
Type Example
plot(mtcars$disp,mtcars$mpg)
barchart bar chart x~A or A~x
------------------------------------------ bwplot boxplot x~A or A~x
Lattice Graphs cloud 3D scatterplot z~x*y|A
contourplo 3D contour plot z~x*y
Deepayan Sarkar is the author t
Improve on R graphics by proving better defaults densityplot kernal density plot ~x|A*B
dotplot dotplot ~x|A
Easy to display multivariate relations
histogram histogram ~x
Supports Trellis Graphs levelplot 3D level plot z~y*x
Format:graph_type(formula,data=..) stripplot strip plots A~x or x~A
xyplot scatterplot y~x|A
wireframe 3D wireframe z~y*x
Density Plot graph
library(lattice)
gear.f=factor(gear,levels=c(3,4,5),labels=c("3gears","4gears","5gears"))
cyl.f=factor(cyl,levels=c(4,6,8),labels=c("4cyl","6cyl","8cyl"))
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
densityplot(mtcars$mpg,main="Density Plot",xlab="Miles per Gallon")
Dot Plots
1.
# Simple Dotplot
dotchart(mtcars$mpg,labels=row.names(mtcars),cex=.7, main="Gas Milage for Car Models",
xlab="Miles Per Gallon")
---------------------------------------------------------------------------------------------------
2.
# Dotplot: Grouped Sorted and Colored
# Sort by mpg, group and color by cylinder
x <- mtcars[order(mtcars$mpg),] # sort by mpg
x$cyl <- factor(x$cyl) # it must be a factor
x$color[x$cyl==4] <- "red"
x$color[x$cyl==6] <- "blue"
x$color[x$cyl==8] <- "darkgreen"
dotchart(x$mpg,labels=row.names(x),cex=.7,groups= x$cyl,
main="Gas Milage for Car Models\ngrouped by cylinder",
xlab="Miles Per Gallon", gcolor="black", color=x$color)
---------------------------------------------------------------------------------------------------
Bar Plot
1.
# Simple Bar Plot
counts <- table(mtcars$gear)
barplot(counts, main="Car Distribution",
xlab="Number of Gears")
---------------------------------------------------------------------------------------------------
2.
# Simple Horizontal Bar Plot with Added Labels
counts <- table(mtcars$gear)
barplot(counts, main="Car Distribution", horiz=TRUE,
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
names.arg=c("3 Gears", "4 Gears", "5 Gears"))
---------------------------------------------------------------------------------------------------
3.
# 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("darkblue","red"),
legend = rownames(counts))
---------------------------------------------------------------------------------------------------
4. # Fitting Labels
par(las=2) # make label text perpendicular to axis
par(mar=c(5,8,4,2)) # increase y-axis margin.
counts <- table(mtcars$gear)
barplot(counts, main="Car Distribution", horiz=TRUE, names.arg=c("3 Gears", "4 Gears", "5
Gears"), cex.names=0.8)
---------------------------------------------------------------------------------------------------
Line Charts
1.
x <- c(1:5); y <- x # create some data
par(pch=22, col="red") # plotting symbol and color
par(mfrow=c(2,4)) # all plots on one page
opts = c("p","l","o","b","c","s","S","h")
for(i in 1:length(opts)){
heading = paste("type=",opts[i])
plot(x, y, type="n", main=heading)
lines(x, y, type=opts[i])
}
----------------------------------------------------------------------------------------------------------------
2.
x <- c(1:5); y <- x # create some data
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
par(pch=22, col="blue") # plotting symbol and color
par(mfrow=c(2,4)) # all plots on one page
opts = c("p","l","o","b","c","s","S","h")
for(i in 1:length(opts){
heading = paste("type=",opts[i])
plot(x, y, main=heading)
lines(x, y, type=opts[i])
----------------------------------------------------------------------------------------------------------------
3.
# Create Line Chart
# convert factor to numeric for convenience
Orange$Tree <- as.numeric(Orange$Tree)
ntrees <- max(Orange$Tree)
# get the range for the x and y axis
xrange <- range(Orange$age)
yrange <- range(Orange$circumference)
# add lines
for (i in 1:ntrees) {
tree <- subset(Orange, Tree==i)
lines(tree$age, tree$circumference, type="b", lwd=1.5,
lty=linetype[i], col=colors[i], pch=plotchar[i])
}
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
# add a title and subtitle
title("Tree Growth", "example of line plot")
# add a legend
legend(xrange[1], yrange[2], 1:ntrees, cex=0.8, col=colors,
pch=plotchar, lty=linetype, title="Tree")
----------------------------------------------------------------------------------------------------------------
Pie Charts
1.
# Simple Pie Chart
slices <- c(10, 12,4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")
pie(slices, labels = lbls, main="Pie Chart of Countries")
----------------------------------------------------------------------------------------------------------------
2.
# Pie Chart with Percentages
slices <- c(10, 12, 4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")
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="Pie Chart of Countries")
----------------------------------------------------------------------------------------------------------------
3.
# 3D Exploded Pie Chart
library(plotrix)
slices <- c(10, 12, 4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")
pie3D(slices,labels=lbls,explode=0.1,
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
main="Pie Chart of Countries ")
----------------------------------------------------------------------------------------------------------------
4.
# 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)")
----------------------------------------------------------------------------------------------------------------
BoxPlot
1.
# Boxplot of MPG by Car Cylinders
boxplot(mpg~cyl,data=mtcars, main="Car Milage Data",
xlab="Number of Cylinders", ylab="Miles Per Gallon")
----------------------------------------------------------------------------------------------------------------
2.
# Notched Boxplot of Tooth Growth Against 2 Crossed Factors
# boxes colored for ease of interpretation
boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE,
col=(c("gold","darkgreen")),
main="Tooth Growth", xlab="Suppliment and Dose")
----------------------------------------------------------------------------------------------------------------
3.
# Violin Plots
library(vioplot)
x1 <- mtcars$mpg[mtcars$cyl==4]
x2 <- mtcars$mpg[mtcars$cyl==6]
x3 <- mtcars$mpg[mtcars$cyl==8]
vioplot(x1, x2, x3, names=c("4 cyl", "6 cyl", "8 cyl"),
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
col="gold")
title("Violin Plots of Miles Per Gallon")
----------------------------------------------------------------------------------------------------------------
4.
# Example of a Bagplot
library(aplpack)
attach(mtcars)
bagplot(wt,mpg, xlab="Car Weight", ylab="Miles Per Gallon",
main="Bagplot Example")
----------------------------------------------------------------------------------------------------------------
Scatter Plot
1.
# Simple Scatterplot
attach(mtcars)
plot(wt, mpg, main="Scatterplot Example",
xlab="Car Weight ", ylab="Miles Per Gallon ", pch=19)
----------------------------------------------------------------------------------------------------------------
2. # Simple Scatterplot
attach(mtcars)
plot(wt, mpg, main="Scatterplot Example",
xlab="Car Weight ", ylab="Miles Per Gallon ", pch=19)
----------------------------------------------------------------------------------------------------------------
3.
# Add fit lines
abline(lm(mpg~wt), col="red") # regression line (y~x)
lines(lowess(wt,mpg), col="blue") # lowess line (x,y)
----------------------------------------------------------------------------------------------------------------
4.
# Scatterplot Matrices from the glus Package
library(gclus)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
dta <- mtcars[c(1,3,5,6)] # get data
dta.r <- abs(cor(dta)) # get correlations
dta.col <- dmat.color(dta.r) # get colors
# reorder variables so those with highest correlation
# are closest to the diagonal
dta.o <- order.single(dta.r)
cpairs(dta, dta.o, panel.colors=dta.col, gap=.5,
main="Variables Ordered and Colored by Correlation" )
----------------------------------------------------------------------------------------------------------------
5.
# High Density Scatterplot with Binning
library(hexbin)
x <- rnorm(1000)
y <- rnorm(1000)
bin<-hexbin(x, y, xbins=50)
plot(bin, main="Hexagonal Binning")
----------------------------------------------------------------------------------------------------------------
6.
# High Density Scatterplot with Color Transparency
pdf("c:/scatterplot.pdf")
x <- rnorm(1000)
y <- rnorm(1000)
plot(x,y, main="PDF Scatterplot Example", col=rgb(0,100,0,50,maxColorValue=255),
pch=16)
----------------------------------------------------------------------------------------------------------------
7.
# 3D Scatterplot
library(scatterplot3d)
attach(mtcars)
scatterplot3d(wt,disp,mpg, main="3D Scatterplot")
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
----------------------------------------------------------------------------------------------------------------
8.
# 3D Scatterplot with Coloring and Vertical Drop Lines
library(scatterplot3d)
attach(mtcars)
scatterplot3d(wt,disp,mpg, pch=16, highlight.3d=TRUE,
type="h", main="3D Scatterplot")
----------------------------------------------------------------------------------------------------------------
9.
# 3D Scatterplot with Coloring and Vertical Lines
# and Regression Plane
library(scatterplot3d)
attach(mtcars)
s3d <-scatterplot3d(wt,disp,mpg, pch=16, highlight.3d=TRUE,
type="h", main="3D Scatterplot")
fit <- lm(mpg ~ wt+disp)
s3d$plane3d(fit)
----------------------------------------------------------------------------------------------------------------
10.
# Spinning 3d Scatterplot
library(rgl)
plot3d(wt, disp, mpg, col="red", size=3)
----------------------------------------------------------------------------------------------------------------
11.
# Another Spinning 3d Scatterplot
library(Rcmdr)
attach(mtcars)
scatter3d(wt, disp, mpg)
----------------------------------------------------------------------------------------------------------------
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
Graphics
1.
# Set a graphical parameter using par()
par() # view current settings
opar <- par() # make a copy of current settings
par(col.lab="red") # red x and y labels
hist(mtcars$mpg) # create a plot with these new settings
par(opar) # restore original settings
# Set a graphical parameter within the plotting function
hist(mtcars$mpg, col.lab="red")
----------------------------------------------------------------------------------------------------------------
2.
# Type family examples - creating new mappings
plot(1:10,1:10,type="n")
windowsFonts(
A=windowsFont("Arial Black"),
B=windowsFont("Bookman Old Style"),
C=windowsFont("Comic Sans MS"),
D=windowsFont("Symbol")
)
text(3,3,"Hello World Default")
text(4,4,family="A","Hello World from Arial Black")
text(5,5,family="B","Hello World from Bookman Old Style")
text(6,6,family="C","Hello World from Comic Sans MS")
text(7,7,family="D", "Hello World from Symbol")
----------------------------------------------------------------------------------------------------------------
3.
# Example of labeling points
attach(mtcars)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
plot(wt, mpg, main="Milage vs. Car Weight",
xlab="Weight", ylab="Mileage", pch=18, col="blue")
text(wt, mpg, row.names(mtcars), cex=0.6, pos=4, col="red")
----------------------------------------------------------------------------------------------------------------
4.
# A Silly Axis Example
# specify the data
x <- c(1:10); y <- x; z <- 10/x
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
----------------------------------------------------------------------------------------------------------------
5.
# Legend Example
attach(mtcars)
boxplot(mpg~cyl, main="Milage by Car Weight",
yaxt="n", xlab="Milage", horizontal=TRUE,
col=terrain.colors(3))
legend("topright", inset=.05, title="Number of Cylinders",
c("4","6","8"), fill=terrain.colors(3), horiz=TRUE)
----------------------------------------------------------------------------------------------------------------
6.
# 4 figures arranged in 2 rows and 2 columns
attach(mtcars)
par(mfrow=c(2,2))
plot(wt,mpg, main="Scatterplot of wt vs. mpg")
plot(wt,disp, main="Scatterplot of wt vs disp")
hist(wt, main="Histogram of wt")
boxplot(wt, main="Boxplot of wt")
----------------------------------------------------------------------------------------------------------------
7.
# 3 figures arranged in 3 rows and 1 column
attach(mtcars)
par(mfrow=c(3,1))
hist(wt)
hist(mpg)
hist(disp)
----------------------------------------------------------------------------------------------------------------
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
8.
# One figure in row 1 and two figures in row 2
attach(mtcars)
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
hist(wt)
hist(mpg)
hist(disp)
----------------------------------------------------------------------------------------------------------------
9.
# Add boxplots to a scatterplot
par(fig=c(0,0.8,0,0.8), new=TRUE)
plot(mtcars$wt, mtcars$mpg, xlab="Car Weight",
ylab="Miles Per Gallon")
par(fig=c(0,0.8,0.55,1), new=TRUE)
boxplot(mtcars$wt, horizontal=TRUE, axes=FALSE)
par(fig=c(0.65,1,0,0.8),new=TRUE)
boxplot(mtcars$mpg, axes=FALSE)
mtext("Enhanced Scatterplot", side=3, outer=TRUE, line=-3)
----------------------------------------------------------------------------------------------------------------
Lattices
1.
# Lattice Examples
library(lattice)
attach(mtcars)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
cyl.f <-factor(cyl,levels=c(4,6,8),
labels=c("4cyl","6cyl","8cyl"))
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
# 3d scatterplot by factor level
cloud(mpg~wt*qsec|cyl.f,
main="3D Scatterplot by Cylinders")
# scatterplot matrix
splom(mtcars[c(1,3,4,5,6)],
main="MTCARS Data")
----------------------------------------------------------------------------------------------------------------
2.
# Customized Lattice Example
library(lattice)
panel.smoother <- function(x, y) {
panel.xyplot(x, y) # show points
panel.loess(x, y) # show smoothed line
}
attach(mtcars)
hp <- cut(hp,3) # divide horse power into three bands
xyplot(mpg~wt|hp, scales=list(cex=.8, col="red"),
panel=panel.smoother,
xlab="Weight", ylab="Miles per Gallon",
main="MGP vs Weight by Horse Power")
----------------------------------------------------------------------------------------------------------------
ggplot2
1.
# ggplot2 examples
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
library(ggplot2)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
qplot(gear, mpg, data=mtcars, geom=c("boxplot", "jitter"),
fill=gear, main="Mileage by Gear Number",
xlab="", ylab="Miles per Gallon")
----------------------------------------------------------------------------------------------------------------
2.
library(ggplot2)
Probability Plots
1. # Display the Student's t distributions with various
# degrees of freedom and compare to the normal distribution
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
labels <- c("df=1", "df=3", "df=8", "df=30", "normal")
for (i in 1:4){
lines(x, dt(x,degf[i]), lwd=2, col=colors[i])
}
mean=100; sd=15
lb=80; ub=120
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd)
result <- paste("P(",lb,"< IQ <",ub,") =",
signif(area, digits=3))
mtext(result,3)
axis(1, at=seq(40, 160, 20), pos=0)
----------------------------------------------------------------------------------------------------------------
3.
# Q-Q plots
par(mfrow=c(1,2))
# normal fit
qqnorm(x); qqline(x)
# t(3Df) fit
qqplot(rt(1000,df=3), x, main="t(3) Q-Q Plot",
ylab="Sample Quantiles")
abline(0,1)
----------------------------------------------------------------------------------------------------------------
4.
# Estimate parameters assuming log-Normal distribution
# estimate paramters
library(MASS)
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
fitdistr(x, "lognormal")
----------------------------------------------------------------------------------------------------------------
# Mosaic Plot Example
1.
library(vcd)
mosaic(HairEyeColor, shade=TRUE, legend=TRUE)
----------------------------------------------------------------------------------------------------------------
2.
# Association Plot Example
library(vcd)
assoc(HairEyeColor, shade=TRUE)
----------------------------------------------------------------------------------------------------------------
Correlogram
1.
# First Correlogram Example
library(corrgram)
corrgram(mtcars, order=TRUE, lower.panel=panel.shade,upper.panel=panel.pie,
text.panel=panel.txt,main="Car Milage Data in PC2/PC1 Order")
----------------------------------------------------------------------------------------------------------------
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli
3. # Third Correlogram Example
corrgram(mtcars, order=NULL, lower.panel=panel.shade,
upper.panel=NULL, text.panel=panel.txt,
main="Car Milage Data (unsorted)")
----------------------------------------------------------------------------------------------------------------
Dr.A. Pappu Rajan - Associate Professor – St. Joseph’s Institute of Management , Tiruchirappalli