Category Archives: Graphical Methods

The alternative Western bar chart

## [1] "DAL"
str(DAL)
## An 'xts' object on 2007-05-03/2016-03-21 containing:
##   Data: num [1:2237, 1:6] 21.8 21.2 21.2 20 19.8 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:6] "DAL.Open" "DAL.High" "DAL.Low" "DAL.Close" ...
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
## List of 2
##  $ src    : chr "yahoo"
##  $ updated: POSIXct[1:1], format: "2016-03-22 10:30:25"
head(DAL)
##            DAL.Open DAL.High DAL.Low DAL.Close DAL.Volume DAL.Adjusted
## 2007-05-03    21.75    21.95   20.55     20.72    8052800     20.18692
## 2007-05-04    21.25    21.35   20.70     20.98    5437300     20.44023
## 2007-05-07    21.20    21.29   20.20     20.36    2646300     19.83619
## 2007-05-08    20.00    20.00   19.30     19.63    4166100     19.12496
## 2007-05-09    19.75    20.20   19.63     19.79    7541100     19.28085
## 2007-05-10    19.79    19.99   19.55     19.70    3170600     19.19317
barChart(DAL,subset='2016-01::2016',
         theme='white.mono', bar.type='ohlc', TA=NULL)

plot of chunk unnamed-chunk-3

The time symbolic candlestick chart

## [1] "DAL"
str(DAL)
## An 'xts' object on 2007-05-03/2016-03-18 containing:
##   Data: num [1:2236, 1:6] 21.8 21.2 21.2 20 19.8 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:6] "DAL.Open" "DAL.High" "DAL.Low" "DAL.Close" ...
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
## List of 2
##  $ src    : chr "yahoo"
##  $ updated: POSIXct[1:1], format: "2016-03-21 10:07:01"
head(DAL)
##            DAL.Open DAL.High DAL.Low DAL.Close DAL.Volume DAL.Adjusted
## 2007-05-03    21.75    21.95   20.55     20.72    8052800     20.18692
## 2007-05-04    21.25    21.35   20.70     20.98    5437300     20.44023
## 2007-05-07    21.20    21.29   20.20     20.36    2646300     19.83619
## 2007-05-08    20.00    20.00   19.30     19.63    4166100     19.12496
## 2007-05-09    19.75    20.20   19.63     19.79    7541100     19.28085
## 2007-05-10    19.79    19.99   19.55     19.70    3170600     19.19317
candleChart(DAL,subset='2016-01::2016',theme="white",TA=NULL) 

plot of chunk unnamed-chunk-3

The naive pie chart

library(MASS)
str(survey)
## 'data.frame':    237 obs. of  12 variables:
##  $ Sex   : Factor w/ 2 levels "Female","Male": 1 2 2 2 2 1 2 1 2 2 ...
##  $ Wr.Hnd: num  18.5 19.5 18 18.8 20 18 17.7 17 20 18.5 ...
##  $ NW.Hnd: num  18 20.5 13.3 18.9 20 17.7 17.7 17.3 19.5 18.5 ...
##  $ W.Hnd : Factor w/ 2 levels "Left","Right": 2 1 2 2 2 2 2 2 2 2 ...
##  $ Fold  : Factor w/ 3 levels "L on R","Neither",..: 3 3 1 3 2 1 1 3 3 3 ...
##  $ Pulse : int  92 104 87 NA 35 64 83 74 72 90 ...
##  $ Clap  : Factor w/ 3 levels "Left","Neither",..: 1 1 2 2 3 3 3 3 3 3 ...
##  $ Exer  : Factor w/ 3 levels "Freq","None",..: 3 2 2 2 3 3 1 1 3 3 ...
##  $ Smoke : Factor w/ 4 levels "Heavy","Never",..: 2 4 3 2 2 2 2 2 2 2 ...
##  $ Height: num  173 178 NA 160 165 ...
##  $ M.I   : Factor w/ 2 levels "Imperial","Metric": 2 1 NA 2 2 1 1 2 2 2 ...
##  $ Age   : num  18.2 17.6 16.9 20.3 23.7 ...
head(survey)
##      Sex Wr.Hnd NW.Hnd W.Hnd    Fold Pulse    Clap Exer Smoke Height
## 1 Female   18.5   18.0 Right  R on L    92    Left Some Never 173.00
## 2   Male   19.5   20.5  Left  R on L   104    Left None Regul 177.80
## 3   Male   18.0   13.3 Right  L on R    87 Neither None Occas     NA
## 4   Male   18.8   18.9 Right  R on L    NA Neither None Never 160.00
## 5   Male   20.0   20.0 Right Neither    35   Right Some Never 165.00
## 6 Female   18.0   17.7 Right  L on R    64   Right Some Never 172.72
##        M.I    Age
## 1   Metric 18.250
## 2 Imperial 17.583
## 3     <NA> 16.917
## 4   Metric 20.333
## 5   Metric 23.667
## 6 Imperial 21.000
Exer = survey$Exer
Exer.freq = table(Exer)
pie(Exer.freq)

plot of chunk unnamed-chunk-3

The cartographer CA plot

library(ca)
library(vcdExtra)
str(Gilby)
##  table [1:6, 1:4] 33 48 113 209 194 39 41 100 202 255 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ Dullness: chr [1:6] "Ment. defective" "Slow" "Slow Intell" "Fairly Intell" ...
##   ..$ Clothing: chr [1:4] "V.Well clad" "Well clad" "Passable" "Insufficient"
head(Gilby)
##                  Clothing
## Dullness          V.Well clad Well clad Passable Insufficient
##   Ment. defective          33        41       39           17
##   Slow                     48       100       58           13
##   Slow Intell             113       202       70           22
##   Fairly Intell           209       255       61           10
##   Capable                 194       138       33           10
##   V.Able                   39        15        4            1
plot(ca(Gilby))

plot of chunk unnamed-chunk-3

The intriguing parallel coordinates plot

library(MASS)
str(USJudgeRatings)
## 'data.frame':    43 obs. of  12 variables:
##  $ CONT: num  5.7 6.8 7.2 6.8 7.3 6.2 10.6 7 7.3 8.2 ...
##  $ INTG: num  7.9 8.9 8.1 8.8 6.4 8.8 9 5.9 8.9 7.9 ...
##  $ DMNR: num  7.7 8.8 7.8 8.5 4.3 8.7 8.9 4.9 8.9 6.7 ...
##  $ DILG: num  7.3 8.5 7.8 8.8 6.5 8.5 8.7 5.1 8.7 8.1 ...
##  $ CFMG: num  7.1 7.8 7.5 8.3 6 7.9 8.5 5.4 8.6 7.9 ...
##  $ DECI: num  7.4 8.1 7.6 8.5 6.2 8 8.5 5.9 8.5 8 ...
##  $ PREP: num  7.1 8 7.5 8.7 5.7 8.1 8.5 4.8 8.4 7.9 ...
##  $ FAMI: num  7.1 8 7.5 8.7 5.7 8 8.5 5.1 8.4 8.1 ...
##  $ ORAL: num  7.1 7.8 7.3 8.4 5.1 8 8.6 4.7 8.4 7.7 ...
##  $ WRIT: num  7 7.9 7.4 8.5 5.3 8 8.4 4.9 8.5 7.8 ...
##  $ PHYS: num  8.3 8.5 7.9 8.8 5.5 8.6 9.1 6.8 8.8 8.5 ...
##  $ RTEN: num  7.8 8.7 7.8 8.7 4.8 8.6 9 5 8.8 7.9 ...
head(USJudgeRatings)
##                CONT INTG DMNR DILG CFMG DECI PREP FAMI ORAL WRIT PHYS RTEN
## AARONSON,L.H.   5.7  7.9  7.7  7.3  7.1  7.4  7.1  7.1  7.1  7.0  8.3  7.8
## ALEXANDER,J.M.  6.8  8.9  8.8  8.5  7.8  8.1  8.0  8.0  7.8  7.9  8.5  8.7
## ARMENTANO,A.J.  7.2  8.1  7.8  7.8  7.5  7.6  7.5  7.5  7.3  7.4  7.9  7.8
## BERDON,R.I.     6.8  8.8  8.5  8.8  8.3  8.5  8.7  8.7  8.4  8.5  8.8  8.7
## BRACKEN,J.J.    7.3  6.4  4.3  6.5  6.0  6.2  5.7  5.7  5.1  5.3  5.5  4.8
## BURNS,E.B.      6.2  8.8  8.7  8.5  7.9  8.0  8.1  8.0  8.0  8.0  8.6  8.6
parcoord(USJudgeRatings)

plot of chunk unnamed-chunk-3

The painter artist heat map

library(gplots)
str(USJudgeRatings)
## 'data.frame':    43 obs. of  12 variables:
##  $ CONT: num  5.7 6.8 7.2 6.8 7.3 6.2 10.6 7 7.3 8.2 ...
##  $ INTG: num  7.9 8.9 8.1 8.8 6.4 8.8 9 5.9 8.9 7.9 ...
##  $ DMNR: num  7.7 8.8 7.8 8.5 4.3 8.7 8.9 4.9 8.9 6.7 ...
##  $ DILG: num  7.3 8.5 7.8 8.8 6.5 8.5 8.7 5.1 8.7 8.1 ...
##  $ CFMG: num  7.1 7.8 7.5 8.3 6 7.9 8.5 5.4 8.6 7.9 ...
##  $ DECI: num  7.4 8.1 7.6 8.5 6.2 8 8.5 5.9 8.5 8 ...
##  $ PREP: num  7.1 8 7.5 8.7 5.7 8.1 8.5 4.8 8.4 7.9 ...
##  $ FAMI: num  7.1 8 7.5 8.7 5.7 8 8.5 5.1 8.4 8.1 ...
##  $ ORAL: num  7.1 7.8 7.3 8.4 5.1 8 8.6 4.7 8.4 7.7 ...
##  $ WRIT: num  7 7.9 7.4 8.5 5.3 8 8.4 4.9 8.5 7.8 ...
##  $ PHYS: num  8.3 8.5 7.9 8.8 5.5 8.6 9.1 6.8 8.8 8.5 ...
##  $ RTEN: num  7.8 8.7 7.8 8.7 4.8 8.6 9 5 8.8 7.9 ...
head(USJudgeRatings)
##                CONT INTG DMNR DILG CFMG DECI PREP FAMI ORAL WRIT PHYS RTEN
## AARONSON,L.H.   5.7  7.9  7.7  7.3  7.1  7.4  7.1  7.1  7.1  7.0  8.3  7.8
## ALEXANDER,J.M.  6.8  8.9  8.8  8.5  7.8  8.1  8.0  8.0  7.8  7.9  8.5  8.7
## ARMENTANO,A.J.  7.2  8.1  7.8  7.8  7.5  7.6  7.5  7.5  7.3  7.4  7.9  7.8
## BERDON,R.I.     6.8  8.8  8.5  8.8  8.3  8.5  8.7  8.7  8.4  8.5  8.8  8.7
## BRACKEN,J.J.    7.3  6.4  4.3  6.5  6.0  6.2  5.7  5.7  5.1  5.3  5.5  4.8
## BURNS,E.B.      6.2  8.8  8.7  8.5  7.9  8.0  8.1  8.0  8.0  8.0  8.6  8.6
heatmap.2(as.matrix(USJudgeRatings), 
          scale = "column", 
          trace="none", 
          main = "USJudgeRatings data")

plot of chunk unnamed-chunk-3

The exploratory matrix of scatterplots

library(graphics)
str(USJudgeRatings)
## 'data.frame':    43 obs. of  12 variables:
##  $ CONT: num  5.7 6.8 7.2 6.8 7.3 6.2 10.6 7 7.3 8.2 ...
##  $ INTG: num  7.9 8.9 8.1 8.8 6.4 8.8 9 5.9 8.9 7.9 ...
##  $ DMNR: num  7.7 8.8 7.8 8.5 4.3 8.7 8.9 4.9 8.9 6.7 ...
##  $ DILG: num  7.3 8.5 7.8 8.8 6.5 8.5 8.7 5.1 8.7 8.1 ...
##  $ CFMG: num  7.1 7.8 7.5 8.3 6 7.9 8.5 5.4 8.6 7.9 ...
##  $ DECI: num  7.4 8.1 7.6 8.5 6.2 8 8.5 5.9 8.5 8 ...
##  $ PREP: num  7.1 8 7.5 8.7 5.7 8.1 8.5 4.8 8.4 7.9 ...
##  $ FAMI: num  7.1 8 7.5 8.7 5.7 8 8.5 5.1 8.4 8.1 ...
##  $ ORAL: num  7.1 7.8 7.3 8.4 5.1 8 8.6 4.7 8.4 7.7 ...
##  $ WRIT: num  7 7.9 7.4 8.5 5.3 8 8.4 4.9 8.5 7.8 ...
##  $ PHYS: num  8.3 8.5 7.9 8.8 5.5 8.6 9.1 6.8 8.8 8.5 ...
##  $ RTEN: num  7.8 8.7 7.8 8.7 4.8 8.6 9 5 8.8 7.9 ...
head(USJudgeRatings)
##                CONT INTG DMNR DILG CFMG DECI PREP FAMI ORAL WRIT PHYS RTEN
## AARONSON,L.H.   5.7  7.9  7.7  7.3  7.1  7.4  7.1  7.1  7.1  7.0  8.3  7.8
## ALEXANDER,J.M.  6.8  8.9  8.8  8.5  7.8  8.1  8.0  8.0  7.8  7.9  8.5  8.7
## ARMENTANO,A.J.  7.2  8.1  7.8  7.8  7.5  7.6  7.5  7.5  7.3  7.4  7.9  7.8
## BERDON,R.I.     6.8  8.8  8.5  8.8  8.3  8.5  8.7  8.7  8.4  8.5  8.8  8.7
## BRACKEN,J.J.    7.3  6.4  4.3  6.5  6.0  6.2  5.7  5.7  5.1  5.3  5.5  4.8
## BURNS,E.B.      6.2  8.8  8.7  8.5  7.9  8.0  8.1  8.0  8.0  8.0  8.6  8.6
pairs(USJudgeRatings[1:4], main = "USJudgeRatings data")

plot of chunk unnamed-chunk-3

The multiple faceted correlogram

str(Baseball)
## 'data.frame':    322 obs. of  25 variables:
##  $ name1   : chr  "Al" "Alan" "Alan" "Alan" ...
##  $ name2   : chr  "Newman" "Ashby" "Trammell" "Wiggins" ...
##  $ atbat86 : int  185 315 574 239 202 594 479 496 401 321 ...
##  $ hits86  : int  37 81 159 60 53 169 130 141 92 87 ...
##  $ homer86 : int  1 7 21 0 4 4 18 20 17 10 ...
##  $ runs86  : int  23 24 107 30 31 74 66 65 49 39 ...
##  $ rbi86   : int  8 38 75 11 26 51 72 78 66 42 ...
##  $ walks86 : int  21 39 59 22 27 35 76 37 65 30 ...
##  $ years   : int  2 14 10 6 9 11 3 11 13 2 ...
##  $ atbat   : int  214 3449 4631 1941 1876 4408 1624 5628 5206 396 ...
##  $ hits    : int  42 835 1300 510 467 1133 457 1575 1332 101 ...
##  $ homeruns: int  1 69 90 4 15 19 63 225 253 12 ...
##  $ runs    : int  30 321 702 309 192 501 224 828 784 48 ...
##  $ rbi     : int  9 414 504 103 186 336 266 838 890 46 ...
##  $ walks   : int  24 375 488 207 161 194 263 354 866 33 ...
##  $ league86: Factor w/ 2 levels "A","N": 2 2 1 1 2 1 1 2 1 2 ...
##  $ div86   : Factor w/ 2 levels "E","W": 1 2 1 1 2 2 2 1 1 1 ...
##  $ team86  : Factor w/ 24 levels "Atl","Bal","Bos",..: 14 9 8 2 11 16 21 14 7 14 ...
##  $ posit86 : Factor w/ 25 levels "13","1B","1O",..: 5 11 24 5 11 24 2 22 15 2 ...
##  $ outs86  : int  76 632 238 121 304 282 880 200 0 805 ...
##  $ assist86: int  127 43 445 151 45 421 82 11 0 40 ...
##  $ error86 : int  7 10 22 6 11 25 14 3 0 4 ...
##  $ sal87   : num  70 475 517 700 512 ...
##  $ league87: Factor w/ 2 levels "A","N": 1 2 1 1 2 1 1 2 1 2 ...
##  $ team87  : Factor w/ 24 levels "Atl","Bal","Bos",..: 13 9 8 2 11 16 21 5 7 14 ...
head(Baseball)
##     name1    name2 atbat86 hits86 homer86 runs86 rbi86 walks86 years atbat
## 1      Al   Newman     185     37       1     23     8      21     2   214
## 2    Alan    Ashby     315     81       7     24    38      39    14  3449
## 3    Alan Trammell     574    159      21    107    75      59    10  4631
## 4    Alan  Wiggins     239     60       0     30    11      22     6  1941
## 5    Alex  Trevino     202     53       4     31    26      27     9  1876
## 6 Alfredo  Griffin     594    169       4     74    51      35    11  4408
##   hits homeruns runs rbi walks league86 div86 team86 posit86 outs86
## 1   42        1   30   9    24        N     E    Mon      2B     76
## 2  835       69  321 414   375        N     W    Hou       C    632
## 3 1300       90  702 504   488        A     E    Det      SS    238
## 4  510        4  309 103   207        A     E    Bal      2B    121
## 5  467       15  192 186   161        N     W     LA       C    304
## 6 1133       19  501 336   194        A     W    Oak      SS    282
##   assist86 error86   sal87 league87 team87
## 1      127       7  70.000        A    Min
## 2       43      10 475.000        N    Hou
## 3      445      22 517.143        A    Det
## 4      151       6 700.000        A    Bal
## 5       45      11 512.500        N     LA
## 6      421      25 750.000        A    Oak
corrgram(Baseball, order=NULL, lower.panel=panel.shade,
  upper.panel=NULL, text.panel=panel.txt)

plot of chunk unnamed-chunk-3

The serviceable q-q plot

str(trees)
## 'data.frame':    31 obs. of  3 variables:
##  $ Girth : num  8.3 8.6 8.8 10.5 10.7 10.8 11 11 11.1 11.2 ...
##  $ Height: num  70 65 63 72 81 83 66 75 80 75 ...
##  $ Volume: num  10.3 10.3 10.2 16.4 18.8 19.7 15.6 18.2 22.6 19.9 ...
head(trees)
##   Girth Height Volume
## 1   8.3     70   10.3
## 2   8.6     65   10.3
## 3   8.8     63   10.2
## 4  10.5     72   16.4
## 5  10.7     81   18.8
## 6  10.8     83   19.7
qqnorm(trees$Height)
qqline(trees$Height)

plot of chunk unnamed-chunk-3

The Mondrian like mosaic plot

library(vcdExtra)
str(HospVisits)
##  table [1:3, 1:3] 43 6 9 16 11 18 3 10 16
##  - attr(*, "dimnames")=List of 2
##   ..$ visit: chr [1:3] "Regular" "Infrequent" "Never"
##   ..$ stay : chr [1:3] "2-9" "10-19" "20+"
HospVisits
##             stay
## visit        2-9 10-19 20+
##   Regular     43    16   3
##   Infrequent   6    11  10
##   Never        9    18  16
mosaic(HospVisits, gp = shading_Friendly())

plot of chunk unnamed-chunk-3