data(mtcars)
# 1. Frequency table for number of cylinders
cyl_freq <- table(mtcars$cyl)
cyl_freq
# Bar diagrambarplot(cyl_freq,
main="Bar Plot of Cylinders",
xlab="Number of Cylinders",
ylab="Frequency",
col="lightblue")
# Cylinder with highest frequency
max_freq <- max(cyl_freq)
cyl_with_max <- names(cyl_freq[cyl_freq==max_freq])
cyl_with_max
# 2. Histogram for mpg
hist(mtcars$mpg,
main="Histogram of MPG",
xlab="Miles per gallon",
col="lightgreen")
# Find range with least frequency
hist_data <- hist(mtcars$mpg, plot=FALSE)
least_freq_range <- hist_data$breaks[which.min(hist_data$counts)]
least_freq_range
# 3. Five point summary of mpg
summary(mtcars$mpg)
# Boxplot for mpg
boxplot(mtcars$mpg,
main="Boxplot of MPG",
ylab="Miles per gallon",
col="pink")
# 4. Scatterplot of mpg vs wt
plot(mtcars$wt, mtcars$mpg,
main="Scatterplot of MPG vs Weight",
xlab="Weight",
ylab="Miles per gallon",
col="red",
pch=19)
