xxxxxxxxxx
ggplot(mtcars, ## dataset
aes(x = mpg, y = wt, ## dataset columns
color = cyl_factor)) ## categorize by cyl_factor which you should create before
+ geom_point(shape = 19) ## circles shape
+ xlab("Miles per Gallon")
+ ylab("Weight")
+ labs(color = "Cylinders") ## legend title
+ ggtitle("Scatterplot")
)
xxxxxxxxxx
library(ggplot2)
# Basic scatter plot
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()