We’re using package ggplot2 to see correlations between variable displ or engine displacement and hwy highway miles per gallon in data mpg
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
ggplot2 provides several functions that we can use to make plots, as for example is geom_point. In this section we input the function geom_point and set the colour of the plot by variable class to see which car type class that are more efficient interms of engine displacement and how far they can run on highway.
ggplot(data=mpg)+
geom_point(mapping=aes(x=displ, y=hwy, colour=class))
And here’s the plot we get, as we can see 2 seater type car have 7 engine displacement and consume more gallon per miles rather than other car types meanwhile some subcompact type car only have <2 engine displacement and the longest distance they could travel is more than 40 miles