


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
R scripts for creating charts and analyzing the mtcars dataset. The charts show the distribution of cars' MPG, the data distribution based on the number of cylinders and MPG, and the composition of cars based on the number of cylinders and carburetor barrels. The insights gained from the charts are also provided. The document can be useful for students studying data visualization, statistics, and data analysis.
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!
Types of Charts Create your own charts and write the insights! Distribution Script: par ( cex=1. ) hist(mtcars$mpg, col="Red", breaks=9, xlab="MPG", ylab="Frequency", main="Distribution of Cars' MPG" ) Insights: Based on the mtcars dataset, there are many cars that have Miles/(US) Gallon (MPG) in the range of 15 to 21. Script: par ( cex=0. ) boxplot(mpg ~ cyl, data = mtcars, xlab="Number of Cylinders", ylab="MPG", main="Data Distribution Based on The Number of Cylinders and MPG", col="Purple" ) Insights: We can see here on the dataset that the more cylinders a car has, the more likely that car has lower MPG.
Composition Script: par ( cex=0. 8 ) x1 = sum(mtcars$cyl==4) x2 = sum(mtcars$cyl==6) x3 = sum(mtcars$cyl==8) y1 = (x1/(x1+x2+x3))* y2 = (x2/(x1+x2+x3))* y3 = (x3/(x1+x2+x3))* pie( c(y1, y2, y3), labels=c(paste(y1, "%"), paste(y2, "%"), paste(y 3 , "%")), main="Number of Cylinders Composition", col=rainbow( 3 ) ) legend("topleft", c("4 Cylinders", " Cylinders", "8 Cylinders"), fill=rainbow(3)) Insights: Based on the dataset, almost 50% of the cars have 8 cylinders while the other cars have only 4 or 6 cylinders. Script: par ( cex=0. 8 ) x1 = sum(mtcars$carb==1) x2 = sum(mtcars$carb==2) x3 = sum(mtcars$carb==3) x4 = sum(mtcars$carb==4) x5 = sum(mtcars$carb==6) x6 = sum(mtcars$carb==8) y1 = (x1/(x1+x2+x3+x4+x5+x6))* y2 = (x2/(x1+x2+x3+x4+x5+x6))* y3 = (x3/(x1+x2+x3+x4+x5+x6))* y4 = (x4/(x1+x2+x3+x4+x5+x6))* y5 = (x5/(x1+x2+x3+x4+x5+x6))* y6 = (x6/(x1+x2+x3+x4+x5+x6))* pie( c(y1, y2, y3, y4, y5, y6), labels=c(paste(y1, "%"), paste(y2, "%"), paste(y3, "%"), paste(y4, "%"), paste(y5, "%"), paste(y6, "%")), main="Number of Carburetor Barrels Composition", col=rainbow(6) ) legend("topleft", c("1", "2", "3", "4", "6", "8"), fill=rainbow(6)) Insights: Based on the data visualization above, we can see that cars with 4 carburetor barrels are the majority followed by cars with 2 and 1 carburetor barrels.
table, col=c("Red", "Blue", "Green"), xlab="Number of Gears", ylab="Frequency", main="Number of Cars Based on The Number of Gears", ) Insights: Based on the dataset, cars with 3 gears are the majority of cars followed by cars that have 4 and then 5 gears. xlab="Year", ylab="Sunspot Number", main="Sunspot Number from 1700 until 1988" ) Insights: We can see here from the dataset that the sunspot number kept changing up and down very often.