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 software 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.
#Method 1
library(ggplot2)
data(mtcars)
carb_mtCars <-table(mtcars$carb)
percent_value <- round(carb_mtCars *100 / sum(carb_mtCars), 1)
pie(carb_mtCars, labels = percent_value, main="Proportions of cars by 'carb' value")

#Method2
ggplot(data=mtcars, 
       aes(x = factor(1), fill = factor(carb))) + 
  ylab("Proportions of cars by 'carb' value") + xlab("") +
  geom_bar(width = 1) + 
  coord_polar(theta = "y")

  1. Draw a bar graph, that shows the number of each gear type in mtcars.
gear_data <- table (mtcars$gear)
factor(mtcars$gear)
##  [1] 4 4 4 3 3 3 3 4 4 4 4 3 3 3 3 3 3 4 4 4 3 3 3 3 3 4 5 5 5 5 5 4
## Levels: 3 4 5
 ggplot(data=mtcars, aes(x=gear)) + geom_bar(stat="count") +  
  xlab("Gear Values") +
  ylab("Count of Gear'") +
  geom_bar(color="blue") 

  1. Next show a stacked bar graph of the number of each gear type and how they are further divded out by cyl.
ggplot(mtcars, 
       aes(x = factor(gear), fill = factor(cyl))) +  
  xlab("Gear") +
  ylab("Count of Gear'") +
  geom_bar(color="blue")

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

ggplot(mtcars, aes(x = wt, y = mpg)) +
  xlab("Weight of Car") + ylab("Miles Per Gallon") +
  geom_point() + geom_point(aes(color = factor(mpg)), size = 2)

  1. Design a visualization of your choice using the data.
plot(mtcars$hp, mtcars$mpg, pch = mtcars$am, xlab = "horsepower",
     cex = 1.2, ylab = "miles per gallon", main = "mpg vs. hp by
     transmission")
legend("topright", c("automatic", "manual"), pch = c(0,1))