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.
setwd("~/Desktop")
pie(table(mtcars$carb), main = "Proportion of Cars by Carb", labels = names(table(mtcars$carb)))

setwd("~/Desktop")
knitr::include_graphics("1.jpg")

2. Draw a bar graph, that shows the number of each gear type in mtcars.

mtcars$gear = as.factor(mtcars$gear)
barplot(summary(mtcars$gear), xlab = "Gear Type", ylab = "No. of Gear", main = "Bar Graph of Gear")

knitr::include_graphics("2.jpg")

3. Next show a stacked bar graph of the number of each gear type and how they are further divded out by cyl.

table1 = table(mtcars$cyl, mtcars$gear)
barplot(table1, xlab = "Gear Type", ylab = "No. of Gear", main = "Stacked Bar Graph of Gear", col = (1:3), legend = (row.names(table1)))

knitr::include_graphics("3.jpg")

4. Draw a scatter plot showing the relationship between wt and mpg.

plot(mtcars$wt, mtcars$mpg, xlab = "wt", ylab = "mpg", main = "Scatter Plot of wt vs mpg")

knitr::include_graphics("4.jpg")

5. Design a visualization of your choice using the data.

# Draw a plot showing the relationship between `gear` and `mpg`. 
plot(mtcars$gear, mtcars$mpg, xlab = "gear", ylab = "mpg", main = "Plot of gear vs mpg")

knitr::include_graphics("5.jpg")