UFO Data

ufo <- read.csv("http://www.stat.ufl.edu/~winner/data/ufo_location_shape.csv")
head(ufo)
##   Event.Date               Shape          Location State Country Source USA
## 1  6/18/2016 Boomerang/V-Shaped  South Barrington    IL     USA  NUFORC   1
## 2  6/17/2016 Boomerang/V-Shaped              Kuna    ID     USA  NUFORC   1
## 3  5/30/2016 Boomerang/V-Shaped      Lake Stevens    WA     USA  NUFORC   1
## 4  5/27/2016 Boomerang/V-Shaped            Gerber    CA     USA  NUFORC   1
## 5  5/24/2016 Boomerang/V-Shaped         Camdenton    MO     USA  NUFORC   1
## 6  5/21/2016 Boomerang/V-Shaped    Ft. Lauderdale    FL     USA  NUFORC   1
##   weekday
## 1       7
## 2       6
## 3       2
## 4       6
## 5       3
## 6       7
library(RColorBrewer)
table(ufo$Shape,ufo$weekday)
##                      
##                         1   2   3   4   5   6   7
##   Boomerang/V-Shaped    5   2   6   5   5   5  10
##   Cigar/Cylinder       18  22  21  20  20  11  26
##   Circle               62  59  37  38  64  83 108
##   Cone                  1   1   5   5   3   1   1
##   Cross                 3   1   4   2   0   4   0
##   Diamond               6   6   8   9  10  11   7
##   Disk                 19  37  18  28  27  26  23
##   Egg                   2   1   3   2   1   4   6
##   Fireball             35  27  42  25  47  47  71
##   Lights Only         139 133  97 128 132 195 199
##   Missile/Rocket        0   0   0   1   0   0   0
##   Orb/Sphere           37  52  30  37  49  66  76
##   Other                40  30  35  32  35  29  38
##   Oval                 22  15  11  15  22  17  27
##   Pyramid               0   0   0   2   0   0   0
##   Rectangle            13   5   5  11  11  12  11
##   Sphere                0   1   0   0   0   0   0
##   Square                0   0   0   0   1   0   0
##   Teardrop              3   8   2   4   6   6   7
##   Triangle             56  48  47  33  40  59  53
##   Unknown              46  29  29  32  38  33  50
shape.table <- table(ufo$Shape)
names(shape.table) <- c("V","Cyl","Circ","Cone","Cross","Diam","Disk",
    "Egg","FireB","Lights","Missile","Sphere","Other","Oval","Pyramid",
    "Rect","Sphere2","Square","Tear","Tri","Unk")
shape.table
##       V     Cyl    Circ    Cone   Cross    Diam    Disk     Egg   FireB  Lights 
##      38     138     451      17      14      57     178      19     294    1023 
## Missile  Sphere   Other    Oval Pyramid    Rect Sphere2  Square    Tear     Tri 
##       1     347     239     129       2      68       1       1      36     336 
##     Unk 
##     257
prop.table(shape.table)
##            V          Cyl         Circ         Cone        Cross         Diam 
## 0.0104223807 0.0378496983 0.1236972024 0.0046626440 0.0038398245 0.0156335710 
##         Disk          Egg        FireB       Lights      Missile       Sphere 
## 0.0488206253 0.0052111903 0.0806363138 0.2805814591 0.0002742732 0.0951727921 
##        Other         Oval      Pyramid         Rect      Sphere2       Square 
## 0.0655512891 0.0353812397 0.0005485464 0.0186505760 0.0002742732 0.0002742732 
##         Tear          Tri          Unk 
## 0.0098738343 0.0921557872 0.0704882063
color1 <- brewer.pal(length(shape.table), "Set2")
## Warning in brewer.pal(length(shape.table), "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
pie(shape.table, col=color1, cex=0.5)

barplot(shape.table, col=color1)

weekday.f <- factor(ufo$weekday, levels=1:7, 
                 labels=c("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"))
weekday.table <- table(weekday.f)
color2 <- brewer.pal(length(weekday.table), "Set1")
pie(weekday.table, col=color2, cex=0.5)

barplot(weekday.table, col=color2)

## Disaster Movies

movie <- read.csv("http://www.stat.ufl.edu/~winner/data/movie_disaster.csv")
head(movie)
##                     Movie Movie1 Rating numRate
## 1 Independence Day (1996)  ID4.1      1   11267
## 2                The Core   Core      1    3570
## 3               Armgeddon  Armag      1   11025
## 4             Deep Impact   Deep      1    2790
## 5                Geostorm    Geo      1    5016
## 6             San Andreas SanAnd      1    5500
movie1 <- movie[,-1]

movie.table <- matrix(movie1$numRate,ncol=10)
colnames(movie.table) <- unique(movie1$Rating)
rownames(movie.table) <- unique(movie1$Movie1)
movie.table
##            1     2     3     4     5      6      7      8      9     10
## ID4.1  11267  7116 11267 18976 40917  94880 176121 129274  53963  50405
## Core    3570  3675  6720 11865 21945  25515  17115   7770   2730   4200
## Armag  11025  7938 11466 19845 40572  82908 115542  77616  34398  39690
## Deep    2790  2790  5208 11532 26970  52638  46128  22134   7440   8184
## Geo     5016  5358  7980 12768 22914  26562  17670   7752   2736   5130
## SanAnd  5500  4750  8500 17000 37250  67250  57750  26500   9750  16000
## ID4.2  10360  9435 15170 23865 39035  41070  25345  10545   3515   6660
## M2012  15560 12448 19839 33843 65352  91804  75077  38900  15560  21006
## DayAft  6510  6045 11160 23250 53010 113925 133920  67890  23715  25575
## WarWor 10672  6496 11136 21808 50576 108576 131312  71456  25056  25984
## Pos     2700  2592  4968 10476 22896  30456  18792   7884   2484   4644
## PerfSt  2610  2262  3828  8178 20184  46110  50460  25056   7830   7482
## Twist   2884  2884  4944 10506 25132  51912  54384  28840  10506  14008
## Titan  25200  9600 13200 20400 42000  93600 222000 298800 199200 277200
color3 <- brewer.pal(ncol(movie.table), "Set3")

barplot(t(prop.table(movie.table,1)),beside=T,
    legend=colnames(movie.table),ylim=c(0,1.6), col=color3,
    main="Grouped Bar Plot - Disaster Movies")

barplot(t(prop.table(movie.table,1)),beside=F,
   col=color3,
   main="Stacked Bar Plot - Disaster Movies", ylim=c(0,1.0))