π§Scatter Plot
We can use ggplot2 package to create a scatterplot.
library('palmerpenguins')
library('ggplot2')Penguins dataset has following type of data.

Let's create a scatterplot to see the relation between flipper_length_mm and body_mass_g from this dataset.

Change the color of the points.
Here, we have made the point's color green by specifying the name of the color by color argument inside geome_point function.

Color data points based on a column
Let's say we want to color the data points based on penguin species.
Under geom_point function we added the code aes(color = species) which has changed the color of the point based on the species type from the species column.

Change the shape of a data point based on a column
Let's change the data point shape based on the species column from the penguins dataset.
Here, shape = species argument under geom_point function has changed the data point's shape according to the different species of penguins.

Divide the plot based on groups from a column.
Let's say we want the create different scatter plots for each species. For this purpose, we can subset our data into smaller sections and get graphs for each one.
Here, facet_wrap(~species) functions sub-sectioned the plot based on different species of penguins.

Add a title to the plot
Here, we added the title of the plot by labs function.

Last updated