mtcars
data set that have different carb
values.# place the code to import graphics here
mtcarsCarb <- table(mtcars$carb)
#convert to percentage for each type of carburetor type
percentlabels<- round(100*mtcarsCarb/sum(mtcarsCarb), 1)
#create a label
pielabels<- paste(percentlabels, "%", sep="")
pie(mtcarsCarb, col = rainbow(length(mtcarsCarb)), main = "Pie-chart for carburetors in mtcars dataset", labels = pielabels)
legend("topright", c("Carburetor-1","Carburetor-2","Carburetor-3","Carburetor-4","Carburetor-6","Carburetor-8"), cex=0.6, fill= rainbow(length(mtcarsCarb)))
From the pie-chart shown above, we can see that there are 6 distinct type of carburetors types used by different cars in the mtcars dataset. We can say that carburetor type 2 and type 4 accounts for most(62.8%) of the carburetors type in the dataset. Carburetor type 6 and type 8 accounts for the least popular carburetor types in the mtcars dataset.
gear
type in mtcars
.# place the code to import graphics here
mtcarsGear <- table(mtcars$gear)
barplot(mtcarsGear, main = "Bar Plot for Gears in mtcars dataset", ylab = 'Frequency' ,xlab = "Gear Type", col = rainbow(length(mtcarsGear)))
From the bar chart, we can see that there are three types of gears used by cars in the mtcars dataset, of which the gear type 3 is the most popular.
gear
type and how they are further divided out by cyl
.# place the code to import graphics here
gearCyl <- table(mtcars$cyl, mtcars$gear)
barplot(gearCyl, main = "Stacked BarPlot for MTCars distribution by Gears Vs Cyl", xlab = "Number of Gears",ylab= "Frequency", col = c("blue", "red", "green"), legend = rownames(gearCyl))
From the stacked bar chart shown above, we can see that cars that have gear type 4 doesnot have 8 cylinder engine. Also, cars that have gear type 3 accounts for the highest number of 8 cylinder engines. While cars that have gear type 4 have the highest number of 6 and 4 cylinder engines.
wt
and mpg
.# place the code to import graphics here
plot(mtcars$wt , mtcars$mpg, xlab = 'Weight of Cars', ylab = 'Miles per Gallon', main = 'Scatter Plot for MTCars Weight Vs MPG')
From the scatter-plot, we can see that there is a negative linear relation between the miles per gallon and the weight of the cars, meaning as the weight of a car increases the miles per gallon driven by that decreases. Lighter cars have higher fuel efficiency.
# place the code to import graphics here
plot(mtcars$mpg ~ as.factor(mtcars$vs), mtcars, xlab = "Engine type", ylab="Miles per gallon", main="Boxplot of MTCars MPG vs Engine Type")
The final visualization in this excercise is a boxplot comparision of MPG vs. Engine Type. This visualization is basic and should be used as a part of exploratory analysis of data as it provides the five number summary in a visual format and comparing distribution and spread of data is possible. In the plot below, we can see that engine type 0 has lesser variance/spread than engine type 1. Although, engine type 1 did better in terms of MPG than engine type 0. We can also see that both the boxplots show a significant right skew.