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 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 that have different cylinder (cyl) values.# place the code to import graphics here
library(ggplot2)
ggplot(data = mtcars, aes(x = factor(1),fill = factor(cyl)))+
ylab("Proportion of cars by cylinder")+
xlab("")+
labs(title = "Cylinder Value")+
geom_bar(width =1)+
coord_polar(theta = "y")
From the pie char we can see that major majority cars have 4 and 8 cylinders.
carb type in mtcars.# place the code to import graphics here
ggplot(data = mtcars, aes(x = carb) )+
geom_bar(fill = "blue")+
xlab("carb")+
ylab("Number")+
ggtitle("Number of carb in car")
Car with 2 and 4 carburetors have a highest proportion while cars with 6 and 8 are the at the lowest proportions.
gear type and how they are further divided out by cyl.# place the code to import graphics here
ggplot(data = mtcars, aes (x = factor(cyl), fill = factor(gear)))+
xlab("cyl")+
ylab("Number of gear Type")+
geom_bar(color = "black")+
ggtitle("cyl vs number of gear type")
Car which have 3 and 5 gear can be divided by 3 types of cylinders (4,6,8) and car which have 4 gears can be devided into 2 type of cylinders(4, and 6)
wt and mpg.# place the code to import graphics here
ggplot(data = mtcars , aes ( x =wt, y = mpg))+
geom_point()+
xlab("wt")+
ylab("mpg")+
stat_smooth(method ="loess", formula = y~x, size =1, col = "red")+
ggtitle("Relation between wt & mpg")
From the graph we can say the weight abd mpg are negatively correlated. as weight increass mpg tends to decrease.
# place the code to import graphics here
ggplot(data =mtcars, aes(x =cyl , y = hp ))+
geom_jitter()+
xlab("hp")+
ylab("cyl")+
ggtitle("Relationship between HP vs Number of cyl")
Here I have used a scatter plot to see the relationship between the hp and cyl. From the graph we can see the if horspowers increass when number of cylinder increass. They are positivly correlated.