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 basic steps in the process of making a visualization.

The objective of this assignment is to introduce you to R markdown and to complete and explain basic plots before moving on to more complicated ways to graph data.

The final product of your homework (this file) should include a short summary of each graphic.

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 you will submit the link to that document on Moodle. Please make sure that this link is hyperlinked and that I can see the visualization and the code required to create it.

Questions

Find the mtcars data in R. This is the dataset that you will use to create your graphics.

  1. Create a pie chart showing the proportion of cars from the mtcars data set that have different carb values and write a brief summary.
library(ggplot2)
ggplot(data=mtcars, 
       aes(x = factor(1), fill = factor(carb))) + 
       ylab("Proportions of cars by carb values") + xlab("") +
       geom_bar(width = 1) + 
       coord_polar(theta = "y")

# Values 1,2 & 4 of carb constitue about 80% of the total carb values. This implies that 50% of the possible values(3 out of 6) constitute 80% of the total values
  1. Create a bar graph, that shows the number of each gear type in mtcarsand write a brief summary.
ggplot(data=mtcars, aes(x=gear)) + geom_bar(stat="count") + xlab("Gears") + ylab(" # of Cars")

# Of the total cars in dataset, 15 are 3 geared, 5 are 5 geared and remaining are 4 geared cars
  1. Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyland write a brief summary.
ggplot(mtcars,
aes(x = factor(gear), fill = factor(cyl))) +
xlab("Gears") +
ylab("# of Cars") +
geom_bar(color="black")

# Majority of the 3 geared cars (12 out of 15) have 8 cylinders, whereas majority of 4 geared cars have 4 cylinders. The distribution of types of cylinders in 5 geared cars is evenly distributed between 4 and 8 cylinders with few having 6 cylinders
  1. Draw a scatter plot showing the relationship between wt and mpgand write a brief summary.
plot(mtcars$wt, mtcars$mpg, xlab="Weight", ylab="Miles per Gallon")
title(" Scatter plot of wt vs mpg value", line=1)

# The scatterplot shows that heavier the car lower the Miles per gallon
  1. Design a visualization of your choice using the data and write a brief summary about why you chose that visualization.
plot(mtcars$hp, mtcars$mpg, xlab="Horse Power", ylab="Miles per Gallon")
title(" Scatter plot of hp vs mpg value", line=1)

# The scatterplot shows that heavier the horsepower lower the Miles per gallon