Directions

During ANLY 512 we will be studying the theory and practice of data visualization. We will be using R and the packages within R to assemble data and construct many different types of visualizations. We begin by studying some of the theoretical aspects of visualization. To do that we must appreciate the actual steps in the process of making a visualization.

Most of us use softare to do this and have done so for so long that we have lost an appreciation for the mechanistic steps involved in accurately graphing data. We will fix that this week by creating a series of analog (meaning you draw them by hand) graphics. The visualizations you create must be numerically and visually accurate and precisely scaled. Because of that the data sets we visualize will be small.

The final product of your homework (this file) should include scanned or photographed images for each question below and a short summary of the process.

To submit this homework you will create the document in Rstudio, using the knitr package (button included in Rstudio) and then submit the document to your Rpubs account. Once uploaded your will submit the link to that document on Moodle.

Questions

Find the mtcars data in R. This is the dataset that you will use to create your graphics. Use that data to draw by hand graphics for the next 4 questions.

  1. Draw a pie chart showing the proportion of cars from the mtcars data set that have different carb values.
data("mtcars")
table(mtcars$carb)
## 
##  1  2  3  4  6  8 
##  7 10  3 10  1  1
carb_pct <- prop.table(table(mtcars$carb))*100 # To find the proportions of each carb values.
round(carb_pct, 2)
## 
##     1     2     3     4     6     8 
## 21.88 31.25  9.38 31.25  3.12  3.12
knitr::include_graphics("/Volumes/PNY 16 GB/HU Coursework/ANLY 512/HW 1/IMG_2135.jpg")

  1. Draw a bar graph, that shows the number of each gear type in mtcars.
table(mtcars$gear)
## 
##  3  4  5 
## 15 12  5
knitr::include_graphics("/Volumes/PNY 16 GB/HU Coursework/ANLY 512/HW 1/IMG_2129.jpg")

  1. Next show a stacked bar graph of the number of each gear type and how they are further divded out by cyl.
table(mtcars$gear, by = mtcars$cyl, dnn = c("gear", "cyl") )
##     cyl
## gear  4  6  8
##    3  1  2 12
##    4  8  4  0
##    5  2  1  2
knitr::include_graphics("/Volumes/PNY 16 GB/HU Coursework/ANLY 512/HW 1/IMG_2130.jpg")

  1. Draw a scatter plot showing the relationship between wt and mpg.
df <- mtcars[, c("wt", "mpg")]
head(df)
##                      wt  mpg
## Mazda RX4         2.620 21.0
## Mazda RX4 Wag     2.875 21.0
## Datsun 710        2.320 22.8
## Hornet 4 Drive    3.215 21.4
## Hornet Sportabout 3.440 18.7
## Valiant           3.460 18.1
round(df, 1)
##                      wt  mpg
## Mazda RX4           2.6 21.0
## Mazda RX4 Wag       2.9 21.0
## Datsun 710          2.3 22.8
## Hornet 4 Drive      3.2 21.4
## Hornet Sportabout   3.4 18.7
## Valiant             3.5 18.1
## Duster 360          3.6 14.3
## Merc 240D           3.2 24.4
## Merc 230            3.1 22.8
## Merc 280            3.4 19.2
## Merc 280C           3.4 17.8
## Merc 450SE          4.1 16.4
## Merc 450SL          3.7 17.3
## Merc 450SLC         3.8 15.2
## Cadillac Fleetwood  5.2 10.4
## Lincoln Continental 5.4 10.4
## Chrysler Imperial   5.3 14.7
## Fiat 128            2.2 32.4
## Honda Civic         1.6 30.4
## Toyota Corolla      1.8 33.9
## Toyota Corona       2.5 21.5
## Dodge Challenger    3.5 15.5
## AMC Javelin         3.4 15.2
## Camaro Z28          3.8 13.3
## Pontiac Firebird    3.8 19.2
## Fiat X1-9           1.9 27.3
## Porsche 914-2       2.1 26.0
## Lotus Europa        1.5 30.4
## Ford Pantera L      3.2 15.8
## Ferrari Dino        2.8 19.7
## Maserati Bora       3.6 15.0
## Volvo 142E          2.8 21.4
knitr::include_graphics("/Volumes/PNY 16 GB/HU Coursework/ANLY 512/HW 1/IMG_2132.jpg")

  1. Design a visualization of your choice using the data.
df1 <- mtcars[, c("cyl", "hp")]
head(df1)
##                   cyl  hp
## Mazda RX4           6 110
## Mazda RX4 Wag       6 110
## Datsun 710          4  93
## Hornet 4 Drive      6 110
## Hornet Sportabout   8 175
## Valiant             6 105
# I want to create a bar graph showing average value of horse power for each cylinder value of mtcars.

df_tab <- by(df1$hp, df1$cyl, mean)
df_tab
## df1$cyl: 4
## [1] 82.63636
## -------------------------------------------------------- 
## df1$cyl: 6
## [1] 122.2857
## -------------------------------------------------------- 
## df1$cyl: 8
## [1] 209.2143
round(df_tab, 1)
## df1$cyl: 4
## [1] 82.6
## -------------------------------------------------------- 
## df1$cyl: 6
## [1] 122.3
## -------------------------------------------------------- 
## df1$cyl: 8
## [1] 209.2
knitr::include_graphics("/Volumes/PNY 16 GB/HU Coursework/ANLY 512/HW 1/IMG_2134.jpg")