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
In this section we input the function geom_point and set the colour of the plot by variable class
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