data()

load

data(mtcars)

Print

head(mtcars,10)

To see last rows of the data

tail(mtcars,5)

To see observations

nrow(mtcars)

To see variables

ncol(mtcars)

To see Unique values

first <- with(mtcars, match(unique(carb), carb))

1.Create a pie chart showing the proportion of cars from the mtcars data set that have different carb values.

carb<- table(mtcars$carb)

labels <- paste(names(carb), “”, carb, sep=“”)

pie(carb, labels = labels, border=“black”, radius=0.7, cex=1.2,main=“Proportion of cars with carbs”)

Here from the pie chart we could see that the most proportion of cars are distributed with carb level 2 or 4.

2.Create a bar graph, that shows the number of each gear type in mtcars.

gears <- table(mtcars$gear) barplot(gears, main=“Car Distribution”, xlab=“Number of Gears”)

From the above bar plot we can see that most number of cars have 3 gears.

3. Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyl.

gearscyl <- table(mtcars\(gear, mtcars\)cyl) barplot(gearscyl, main=“Gear type by Cylinder”, xlab=“Number of Gears”, ylab=“Number of Cylinders”, col=c(“darkblue”,“red”), legend = rownames(gears))

The Stacked bar plot shows the number of cylinders distributed amongst the the number of gears per vehicle

4. Draw a scatter plot showing the relationship between wt and mpg.

wt <- mtcars\(wt mpg <- mtcars\)mpg plot(wt, mpg, main=“Scatterplot”, xlab=“Car Weight”, ylab=“Miles Per Gallon”, pch=19)

The scatter plot shows the distribution of vehicles by wt and mpg.

Here we can interpret that as the weight of the car increases mpg decrease.

5. Scatter plot showing the relationship between hp and mpg.

hp <- mtcars\(hp mpg <- mtcars\)mpg plot(hp, mpg, main=“Hp vs Mpg”, xlab=“Horse Power”, ylab=“Miles Per Gallon”, pch=19)

The scatter plot shows the distribution of vehicles by Hp and mpg.

This clearly illustrates that as higher the horsepower lower the mileage per gallon.