Objective

Objective of this document is to cover most of the data visualization solutions availabe in R. We covered different R packages and third party libraries like googleVis etc. Majorly following graphs are covered:

Plotrix Package

R Chart Package

googleVix

Advance Graphics

Shiny Package

Plotrix Package

The package provides specialized plots adn accessories functions to build complex charts easily.

library (plotrix)

# we will use one database titanic1 which is derived from default R database 
# titanic which records all the survivor in titanic tragedy based on their age, # sex and class

# by default barNest will display a black and white charts, but for better 
# visualization we need different colours so first create a colour variable

titanic.colors<-list("gray90",c("#0000ff","#7700ee","#aa00cc","#dd00aa"),
  c("#ddcc00","#ee9900"),c("pink","lightblue"))

barNest (survived ~ class+age+sex, titanic1, col = titanic.colors, showall = TRUE, main= "Titanic survival by class, age and sex", ylab = "Proportion surviving", FUN = "propbrk", shrink = 0.20, trueval="Yes")

colors_plot <- list ("grey", c("blue"))
# So let us first build a dataset with resource names and their expected start # and end week time in a project
data <- list (labels = c ("R1", "R2", "R1", "R3", "R3"),
              starts = c (0, 4, 5, 6, 8), ends = c (3,8,7,7,10))
 
gantt.chart(data,vgridpos=0:10,vgridlab=0:10,main = "Resource allocation",
            taskcolors =c (2,3,7))

- Zoom Plot

Zoom plot helps to see a detailed view of a perticular section of a graph. Viewer can see both the original and detailed view in parallel

zoomInPlot(rnorm(100),rnorm(100),rxlim=c(-1,1),rylim=c(-1,1),
  zoomtitle="Zoom In Plot",titlepos=-1.5)

-Fan Plot
Displays numerical values as the arcs of overlapping sectors.

 data<-data.frame(area=c("Africa","Asia","Europe","N&C America",
  "S America","Oceania"),threatened=c(5994,7737,1987,4716,5097,2093))
 fan.plot(data$threatened,max.span=pi,
  labels=paste(data$area,data$threatened,sep="-"),
  main="Threatened species by geographical area (fan.plot)",ticks=276)

 pieval<-c(2,4,6,8)
 pielabels<-
  c("Pie1","Pie2","Pie3","Pie4")
 lp<-pie3D(pieval,radius=0.9,labels=pielabels,explode=0.1,main="3D PIE OPINIONS")

- Radial Plot

ions <- c(3.2,5,1,3.1,2.1,4.5)
names <- c("Na", "Ca", "Mg","Cl", "HCO3", "SO4")

radial.plot (ions, labels = names, rp.type = "r", main = "Dissolve in water", radial.lim = c(0,7 ), line.col = "blue", lwd = 2)

# draw polygon instead of line
radial.plot (ions, labels = names, rp.type = "p", main = "Dissolve in water", radial.lim = c(0,7 ), line.col = "blue", lwd = 2)

rCharts

s an R package to create, customize and publish interactive javascript visualizations from R using a familiar lattice style plotting interface.

# Need libraries devtools and rChart package to be loaded. If rChart package is not installed already we need to install it also. We will also use one dataset HairEyeColor for our example.

require (devtools)
## Loading required package: devtools
library (rCharts)
# r chart creating issue in showing on HTML so add knitr package
library(knitr)
#View (HairEyeColor)
#get only male data from the dataset 
hair_eye_male <- subset (as.data.frame (HairEyeColor), Sex == "Male")
m1 <- nPlot (Freq ~ Hair ,group = "Eye", data = hair_eye_male,type = "multiBarChart")

opts_chunk$set(comment = NA, results = 'asis', comment = NA, tidy = F)
m1$show('iframesrc', cdn = TRUE)
## <iframe srcdoc=' &lt;!doctype HTML&gt;
## &lt;meta charset = &#039;utf-8&#039;&gt;
## &lt;html&gt;
##   &lt;head&gt;
##     &lt;link rel=&#039;stylesheet&#039; href=&#039;//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.css&#039;&gt;
##     
##     &lt;script src=&#039;//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js&#039; type=&#039;text/javascript&#039;&gt;&lt;/script&gt;
##     &lt;script src=&#039;//d3js.org/d3.v3.min.js&#039; type=&#039;text/javascript&#039;&gt;&lt;/script&gt;
##     &lt;script src=&#039;//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.js&#039; type=&#039;text/javascript&#039;&gt;&lt;/script&gt;
##     &lt;script src=&#039;//nvd3.org/assets/lib/fisheye.js&#039; type=&#039;text/javascript&#039;&gt;&lt;/script&gt;
##     
##     &lt;style&gt;
##     .rChart {
##       display: block;
##       margin-left: auto; 
##       margin-right: auto;
##       width: 800px;
##       height: 400px;
##     }  
##     &lt;/style&gt;
##     
##   &lt;/head&gt;
##   &lt;body &gt;
##     
##     &lt;div id = &#039;chart203419237566&#039; class = &#039;rChart nvd3&#039;&gt;&lt;/div&gt;    
##     &lt;script type=&#039;text/javascript&#039;&gt;
##  $(document).ready(function(){
##       drawchart203419237566()
##     });
##     function drawchart203419237566(){  
##       var opts = {
##  &quot;dom&quot;: &quot;chart203419237566&quot;,
## &quot;width&quot;:    800,
## &quot;height&quot;:    400,
## &quot;x&quot;: &quot;Hair&quot;,
## &quot;y&quot;: &quot;Freq&quot;,
## &quot;group&quot;: &quot;Eye&quot;,
## &quot;type&quot;: &quot;multiBarChart&quot;,
## &quot;id&quot;: &quot;chart203419237566&quot; 
## },
##         data = [
##  {
##  &quot;Hair&quot;: &quot;Black&quot;,
## &quot;Eye&quot;: &quot;Brown&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             32 
## },
## {
##  &quot;Hair&quot;: &quot;Brown&quot;,
## &quot;Eye&quot;: &quot;Brown&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             53 
## },
## {
##  &quot;Hair&quot;: &quot;Red&quot;,
## &quot;Eye&quot;: &quot;Brown&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             10 
## },
## {
##  &quot;Hair&quot;: &quot;Blond&quot;,
## &quot;Eye&quot;: &quot;Brown&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:              3 
## },
## {
##  &quot;Hair&quot;: &quot;Black&quot;,
## &quot;Eye&quot;: &quot;Blue&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             11 
## },
## {
##  &quot;Hair&quot;: &quot;Brown&quot;,
## &quot;Eye&quot;: &quot;Blue&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             50 
## },
## {
##  &quot;Hair&quot;: &quot;Red&quot;,
## &quot;Eye&quot;: &quot;Blue&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             10 
## },
## {
##  &quot;Hair&quot;: &quot;Blond&quot;,
## &quot;Eye&quot;: &quot;Blue&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             30 
## },
## {
##  &quot;Hair&quot;: &quot;Black&quot;,
## &quot;Eye&quot;: &quot;Hazel&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             10 
## },
## {
##  &quot;Hair&quot;: &quot;Brown&quot;,
## &quot;Eye&quot;: &quot;Hazel&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             25 
## },
## {
##  &quot;Hair&quot;: &quot;Red&quot;,
## &quot;Eye&quot;: &quot;Hazel&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:              7 
## },
## {
##  &quot;Hair&quot;: &quot;Blond&quot;,
## &quot;Eye&quot;: &quot;Hazel&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:              5 
## },
## {
##  &quot;Hair&quot;: &quot;Black&quot;,
## &quot;Eye&quot;: &quot;Green&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:              3 
## },
## {
##  &quot;Hair&quot;: &quot;Brown&quot;,
## &quot;Eye&quot;: &quot;Green&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:             15 
## },
## {
##  &quot;Hair&quot;: &quot;Red&quot;,
## &quot;Eye&quot;: &quot;Green&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:              7 
## },
## {
##  &quot;Hair&quot;: &quot;Blond&quot;,
## &quot;Eye&quot;: &quot;Green&quot;,
## &quot;Sex&quot;: &quot;Male&quot;,
## &quot;Freq&quot;:              8 
## } 
## ]
##   
##       if(!(opts.type===&quot;pieChart&quot; || opts.type===&quot;sparklinePlus&quot; || opts.type===&quot;bulletChart&quot;)) {
##         var data = d3.nest()
##           .key(function(d){
##             //return opts.group === undefined ? &#039;main&#039; : d[opts.group]
##             //instead of main would think a better default is opts.x
##             return opts.group === undefined ? opts.y : d[opts.group];
##           })
##           .entries(data);
##       }
##       
##       if (opts.disabled != undefined){
##         data.map(function(d, i){
##           d.disabled = opts.disabled[i]
##         })
##       }
##       
##       nv.addGraph(function() {
##         var chart = nv.models[opts.type]()
##           .width(opts.width)
##           .height(opts.height)
##           
##         if (opts.type != &quot;bulletChart&quot;){
##           chart
##             .x(function(d) { return d[opts.x] })
##             .y(function(d) { return d[opts.y] })
##         }
##           
##          
##         
##           
##         
## 
##         
##         
##         
##       
##        d3.select(&quot;#&quot; + opts.id)
##         .append(&#039;svg&#039;)
##         .datum(data)
##         .transition().duration(500)
##         .call(chart);
## 
##        nv.utils.windowResize(chart.update);
##        return chart;
##       });
##     };
## &lt;/script&gt;
##     
##     &lt;script&gt;&lt;/script&gt;    
##   &lt;/body&gt;
## &lt;/html&gt; ' scrolling='no' frameBorder='0' seamless class='rChart  nvd3  ' id='iframe-chart203419237566'> </iframe>
##  <style>iframe.rChart{ width: 100%; height: 400px;}</style>
#m1$show('inline', include_assets = TRUE, cdn = TRUE)
# View (MASS::survey)
hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, type = c ("line", "bubble", "scatter"), group = "Clap", size = "Age")
Warning in hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, type =
c("line", : Observations with NA has been removed
library(ggplot2)
View (economics)
mPlot (x = "date" , y = c("psavert", "uempmed"), typee = "Line", data = economics)
Loading required package: reshape2
names(iris) = gsub('\\.', '', names(iris))
rPlot(SepalLength ~ SepalWidth | Species, data = iris, type = 'point', color = 'Species')

-xPlot

require(reshape2)
uspexp <- melt(USPersonalExpenditure)
names(uspexp)[1:2] = c('category', 'year')
xPlot(value ~ year, group = 'category', data = uspexp,
type = 'line-dotted')

googleVis