Run the following first in your console to create the data example:
# Load packages
library(dplyr)
library(ggplot2)
# Create data frame
simple_ex <-
data_frame(
A = c(1, 2, 3, 4),
B = c(1, 2, 3, 4),
C = c(3, 2, 1, 2),
D = c("a", "a", "b", "b")
)
Let’s view the data frame, which is in tidy format:
View(simple_ex)
| A | B | C | D |
|---|---|---|---|
| 1 | 1 | 3 | a |
| 2 | 2 | 2 | a |
| 3 | 3 | 1 | b |
| 4 | 4 | 2 | b |
data variables to aes()thetic attributes of geom_etric objects.points as the geom_etric objectlines as the geom_etric objectgeom_etric objects are pointsx-axis is variable Ay-axis is variable Bggplot(data=simple_ex, aes(x=A, y=B)) +
geom_point()
geom_etric objects are pointsx-axis is variable Ay-axis is variable Bcolor is variable Dggplot(data=simple_ex, aes(x=A, y=B, color=D)) +
geom_point()
geom_etric objects are pointsx-axis is variable Ay-axis is variable Bsize is variable Cggplot(data=simple_ex, aes(x=A, y=B, size=C)) +
geom_point()
geom_etric objects are linesx-axis is variable Ay-axis is variable Bggplot(data=simple_ex, aes(x=A, y=B)) +
geom_line()
geom_etric objects are linesx-axis is variable Ay-axis is variable Bcolor is variable Dggplot(data=simple_ex, aes(x=A, y=B, color=D)) +
geom_line()