geom_point | R Documentation |
geom_point
is a geom that should be used in conjunction
with ggplot
to display the relationship between two
continuous variables in a scatterplot. geom_point
will
inherit data and any aesthetic mappings from ggplot()
,
so data only has to be input once.
ggplot(data, aes(x, y)) + geom_point(alpha, color, fill, shape, size, stroke)
data |
A tibble to be used for the scatterplot |
x |
Specify which variable should be drawn on the x-axis. |
y |
Specify which variable should be drawn on the y-axis. |
alpha |
opacity; a number between 0 and 1. It an also be combined with color or fill RGB values through "#RRGGBBAA" where AA = alpha value. |
color |
outer line color of point; can be defined by a variable, color name, or hex code. |
fill |
color inside of point; can be defined by a variable, color name, or hex code. Only shapes 21 - 24 allow for fill. |
shape |
the shape of point; can be identified by an integer, name of shape, or a single character. |
size |
size of point; identified by an integer. The default size is 1.5 |
stroke |
border width of point; identified by integer. |
library(gapminder) # Adjusting the scatterplot shape, color, and fill: gapminder %>% filter(country == "United States") %>% ggplot(aes(x = lifeExp, y = gdpPercap)) + geom_point(shape = 23, color = "purple", fill = "white") # Use hex codes or color names gapminder %>% ggplot(aes(x = gdpPercap, y = lifeExp)) + geom_point( shape = 21, colour = "#33CCFF", fill = "pink", size = 3, stroke = 1 ) # Call `geom_point` twice to layer points gapminder %>% filter(country == "United States") %>% ggplot(aes(x = lifeExp, y = gdpPercap)) + geom_point(aes(color = year), size = 5) + geom_point(color = "grey")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.