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.
A couple of tips, remember that there may be preprocessing involved in your graphics so you may have to do summaries or calculations to prepare, those should be included in your work.
To ensure accuracy pay close attention to axes and labels, you will be evaluated based on the accuracy and expository nature of your graphics.
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 Canvas. Please make sure that this link is hyperlinked and that I can see the visualization and the code required to create it.
Find the mtcars data in R. This is the dataset that you will use to create your graphics.
mtcars data set.# place the code to import graphics here
library('ggplot2')
F1 <- ggplot(mtcars, aes(factor(am, labels = c('Automatic', 'Manual')), qsec)) +
geom_boxplot() +
xlab('Transmission Type') + ylab('1/4 Mile Time (qsec)') +
labs(title = 'Qsec For Different Transmission Types', tag = 'Figure 1')
F1
#Automatic car needs more time for 1/4 mile than manual car (mean, median, etc.)
carb type in mtcars.# place the code to import graphics here
F2 <- barplot(table(mtcars$carb), main = 'Number Of Each Carb', xlab = 'Carb Type', ylab = 'Quantity', col = 'limegreen')
#There are total of 6 carb categories while 2&4 has greatest numbers while 6&8 has the lowest.
gear type and how they are further divided out by cyl.# place the code to import graphics here
F3 <- ggplot(mtcars, aes(factor(gear), fill = factor(cyl))) +
geom_bar() +
ggtitle('Cyclinders For Each Gear Type') +
xlab('Gear Types') +
ylab('Quantities') +
guides(fill = guide_legend(title="Number Of Cylinders ")) +
scale_fill_manual(values = c('red4', 'darkblue', 'lawngreen'))
F3
#We can tell from the chart that most of type 3 cars have 8 cyinders, while most type 4 have 4 cylinders and type 5 have more 4 and 8 cylinders.
wt and mpg.# place the code to import graphics here
F4 <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(size = 2, color = 'firebrick4') +
ggtitle('Relationship Between Weight & Miles Per Gallon') +
xlab('Weight') +
ylab('Miles Per Gallon') +
geom_text(label = rownames(mtcars)) +
geom_smooth(method = 'glm', color = "magenta")
F4
#The graph shows that lighter cars are more fuel economy.
# place the code to import graphics here
F5 <- ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point(size = 3, color = 'black') +
ggtitle('Relationship Between Gross Horsepower & Miles Per Gallon') +
xlab('Gross Horsepower') +
ylab('Miles Per Gallon') +
geom_text(label = rownames(mtcars)) +
geom_smooth(method = 'auto', color = "turquoise1")
F5
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#The graph reflects the relationship between horsepower and fuel economy.
#We can conclude that if you don't want to pay large bill on gas, you may have to sacrifice the horsepower of your car.
#Which means you won't have chance to hear the car roar lOl.