To create a scatter plot, simply define x and y variables inside the aesthetics function and add geom_point()

e.g.

ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_point()

 

gg1

Here, apart from levels of 4, 6 and 8, the graph is also showing 5 and 7 which do not exist. This happens because R is still taking cyl as a numeric. to change this, we have to explicitly tell R that cyl is a factor.

ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_point()

gg2