Scatter Plot
Last updated
Last updated
We can use ggplot2
package to create a scatterplot.
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.
Here, we have made the point's color green by specifying the name of the color by color
argument inside geome_point
function.
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.
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.
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.
Here, we added the title of the plot by labs
function.