Below visualization have been created using mtcars dataset
mtcars
data set that have different carb
values.data("mtcars")
carb_values <- table(mtcars$carb)
carb_values[1]/sum(carb_values)*100
## 1
## 21.875
carb_percent<-c()
for (i in 1:6) {
carb_percent[i] <-as.numeric(carb_values[i]/sum(carb_values)*100)
}
names(carb_percent) <- c("1_carb_percent","2_carb_percent", "3_carb_percent", "4_carb_percent", "6_carb_percent", "8_carb_percent")
pie(carb_percent, names(carb_percent))
gear
type in mtcars
.totalGears <- table(mtcars$gear)
barplot(totalGears, main = " Count v/s Gear", xlab = "Gears", ylab = "Count" , col = c("green","yellow", "brown"))
gear
type and how they are further divded out by cyl
.stack <- table(mtcars$cyl, mtcars$gear)
stack
##
## 3 4 5
## 4 1 8 2
## 6 2 4 1
## 8 12 0 2
barplot(stack, totalGears, xlab = " Gears", ylab= "Count",main = "Stacked barplot of cylinders by gears", col=c("blue","lightgreen","yellow"))
wt
and mpg
.plot(mtcars$wt, mtcars$mpg, main = "mpg v/s wt", ylab = "miles per gallon", xlab = "weight (1000 lbs)")
stack2 <- table(mtcars$am, mtcars$gear)
rownames(stack2) <- c("automatic", "manual")
stack2
##
## 3 4 5
## automatic 15 4 0
## manual 0 8 5
## based on the matrix we can draw a stacked bar plot
barplot(stack2, totalGears, xlab = " Gears", ylab= "Count",main = "Stacked barplot of transmission by gears", col=c("red","lightgreen"))
We can see infer that, all the cars that are 3 gears are automatic transmission and all the 5 gear cara are manual transmission.