#import library
library(RColorBrewer)
  1. Histogram
data(VADeaths)
#View(VADeaths)
par(mfrow=c(2,3))
hist(VADeaths,breaks=10, col=brewer.pal(3,"Set3"),main="Set3 3 colors")
hist(VADeaths,breaks=3 ,col=brewer.pal(3,"Set2"),main="Set2 3 colors")
hist(VADeaths,breaks=7, col=brewer.pal(3,"Set1"),main="Set1 3 colors")
hist(VADeaths,breaks= 2, col=brewer.pal(8,"Set3"),main="Set3 8 colors")
hist(VADeaths,col=brewer.pal(8,"Greys"),main="Greys 8 colors")
hist(VADeaths,col=brewer.pal(8,"Greens"),main="Greens 8 colors")

  1. Bar/ Line Chart
plot(AirPassengers,type="l")  #Simple Line Plot

Bar Chart

par(mfrow=c(3,1))
barplot(iris$Petal.Length) #Creating simple Bar Graph
barplot(iris$Sepal.Length,col  = brewer.pal(3,"Set1"))
barplot(table(iris$Species,iris$Sepal.Length),col  = brewer.pal(3,"Set1")) #Stacked Plot

  1. Box Plot ( including group-by option )
boxplot(iris$Petal.Length~iris$Species) #Creating Box Plot between two variable

data(iris)
par(mfrow=c(2,2))
boxplot(iris$Sepal.Length,col="red")
boxplot(iris$Sepal.Length~iris$Species,col="red")
boxplot(iris$Sepal.Length~iris$Species,col=heat.colors(3))
boxplot(iris$Sepal.Length~iris$Species,col=topo.colors(3))

  1. Scatter Plot (including 3D and other features)
plot(x=iris$Petal.Length) #Simple Scatter Plot

plot(x=iris$Petal.Length,y=iris$Species) #Multivariate Scatter Plot

Scatter Plot Matrix can help visualize multiple variables across each other.

plot(iris,col=brewer.pal(3,"Set1"))

Pie-chart

 pie(table(iris$Species))

Advanced Visualizations What is Hexbin Binning ?

#install.packages("hexbin")
require(ggplot2)
## Loading required package: ggplot2
require(hexbin)
## Loading required package: hexbin
## Warning: package 'hexbin' was built under R version 3.4.3
#data(diamonds)
a=hexbin(diamonds$price,diamonds$carat,xbins=40)
library(RColorBrewer)
plot(a)

library(RColorBrewer)
rf <- colorRampPalette(rev(brewer.pal(40,'Set3')))
## Warning in brewer.pal(40, "Set3"): n too large, allowed maximum for palette Set3 is 12
## Returning the palette you asked for with that many colors
hexbinplot(diamonds$price~diamonds$carat, data=diamonds, colramp=rf)

Mosaic Plot

data(HairEyeColor)
mosaicplot(HairEyeColor)

Heat Map

heatmap(as.matrix(mtcars))

Map Visualization

devtools::install_github("rstudio/leaflet")
## Skipping install of 'leaflet' from a github remote, the SHA1 (d489e2cd) has not changed since last install.
##   Use `force = TRUE` to force installation
require(magrittr)
## Loading required package: magrittr
require(leaflet)
## Loading required package: leaflet
m <- leaflet() %>% 
   addTiles() %>% #Add default OpenStreetMap map tiles
  addMarkers(lng = 77.2310, lat = 28.6560, popup = "The delicious food of chandni chowk")

m

3D Graphs

#install.packages("Rcmdr")

couldn’t able to plot this graph, as Rcmdr getting hanged everytime

#data(iris, package="datasets")
#install.packages("Rcmdr")
#require(Rcmdr)
#scatterplot3d(Petal.Width~Petal.Length+Sepal.Length|Species, data=iris, #fit="linear", 
#residuals=TRUE, parallel=FALSE, bg="black", axis.scales=TRUE, grid=TRUE, #ellipsoid=FALSE)          
attach(iris)# 3d scatterplot by factor level
require(lattice)
## Loading required package: lattice
cloud(Sepal.Length~Sepal.Width*Petal.Length|Species, main="3D Scatterplot by Species")

xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)

Correlogram (GUIs) Correlogram help us visualize the data in correlation matrices. Here’s the code:

cor(iris[1:4])
##              Sepal.Length Sepal.Width Petal.Length Petal.Width
## Sepal.Length    1.0000000  -0.1175698    0.8717538   0.8179411
## Sepal.Width    -0.1175698   1.0000000   -0.4284401  -0.3661259
## Petal.Length    0.8717538  -0.4284401    1.0000000   0.9628654
## Petal.Width     0.8179411  -0.3661259    0.9628654   1.0000000
#install.packages("corrgram")
require(corrgram)
## Loading required package: corrgram
## Warning: package 'corrgram' was built under R version 3.4.3
corrgram(iris)