summary(mtcars)
## mpg cyl disp hp
## Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0
## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5
## Median :19.20 Median :6.000 Median :196.3 Median :123.0
## Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7
## 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0
## Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0
## drat wt qsec vs
## Min. :2.760 Min. :1.513 Min. :14.50 Min. :0.0000
## 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:0.0000
## Median :3.695 Median :3.325 Median :17.71 Median :0.0000
## Mean :3.597 Mean :3.217 Mean :17.85 Mean :0.4375
## 3rd Qu.:3.920 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:1.0000
## Max. :4.930 Max. :5.424 Max. :22.90 Max. :1.0000
## am gear carb
## Min. :0.0000 Min. :3.000 Min. :1.000
## 1st Qu.:0.0000 1st Qu.:3.000 1st Qu.:2.000
## Median :0.0000 Median :4.000 Median :2.000
## Mean :0.4062 Mean :3.688 Mean :2.812
## 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:4.000
## Max. :1.0000 Max. :5.000 Max. :8.000
#To understand the dataset "mtcars" and have an overview of the different variables.
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.library(ggplot2)
Cylinder = factor(mtcars$cyl)
piechart <- ggplot(mtcars, aes(x = factor(1), fill = Cylinder)) + geom_bar()
piechart + coord_polar(theta = "y")
#From the pie chart, we can know that there are three types of cylinders 4, 6, & 8. Of which 8 cylinder cars are more in number.
carb type in mtcars.barchart <- ggplot(mtcars, aes(x = carb)) + geom_bar(width = 0.2)
barchart + ylim(0,10) + xlab("Carburetors") +
ylab("Count")
#From the barplot we see that there are cars with distinct number of carburetors 1, 2, 3, 4, 6, & 8. Among them, cars with carburetors with 2 & 4 are the highest at 10 cars each and 6 & 8 carburetors are the least with 1 car each.
gear type and how they are further divided out by cyl.# place the code to import graphics here
ggplot(mtcars,aes(x=factor(gear),fill=Cylinder)) +
xlab("gear") +
ylab("cylinder") +
geom_bar()
#Among the three different number of gear cars (3, 4, & 5), cars with 4 gear do not have 8 cylinder cars. Whereas 3 gear and 5 gear cars have all the three types of cylinders' cars and 8 cylinder cars are at the highest count. However, 5 gears cars equal number of 4 cylinder cars and 8 cylinder cars.
wt and mpg.#library(ggplot2)
# Basic scatter plot
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
xlab("Weight (1000 lbs)") +
ylab("Mile/(US) gallon")
#We realize from the scatter plot that as the weight of the car increases, the mpg of the car is reducing.
Engine_Shape = factor(mtcars$vs,
levels = 0:1,
labels = c("V-Shaped","Straight"))
ggplot(mtcars,aes(x=factor(Engine_Shape),fill=Cylinder)) +
xlab("Engine Shape") +
ylab("Cylinder") +
geom_bar(width = 0.5)
#I'm interested to visualize the shape of the engine and the number of cylinders in each shape on a stacked bar chart. From the chart we can observe that 8 cylinder cars are not available in the straight engine shape but available in v-shaped engines. We can assume that making a 8 cylinder car on a straight shape engine might be design constraint.