geom_point
The geom_point
function can be used to create a basic scatter plot in ggplot2. Considering the cars
data set you can create the following visualization.
Color
The colour
argument of the geom_point
function allows customizing the color or the points.
Gradient color
If you want to colorize the points based on a value you can pass the variable to the color
(colour
) argument of aes
.
Transparency
The transparency of the points can also be customized with alpha
argument. You can pass a value or a variable, so the transparency will be based on that variable, as in the example below.
Setting show.legend = FALSE
inside geom_point
will remove the legends created automatically when you specify the colour
or alpha
aesthetics or both.
Color scale
If you pass a variable to the colour
argument of the aes
you can customize the color scale with scale_color_gradient
(or a similar function), setting the lower and the higher color value.
Color based on values
The geom_point
function allows coloring the points based on some conditions. Note that you can customize the color of the points with scale_color_manual
.
Shape and size of the points
The shape and the size of the points can be changed with size
and shape
arguments, respectively.
See also