Ryan Juica
- Create a scatterplot of hwy vs. displ where the points are pink filled in triangles.
Warning: package 'dplyr' was built under R version 4.5.3
Warning: package 'lubridate' was built under R version 4.5.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.1 ✔ readr 2.1.6
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.2 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
ggplot(mpg, aes(x = displ, y = hwy, color = "pink")) +
geom_point(shape = 17)
Why did the following code not result in a plot with blue points ggplot(mpg) + geom_point(aes(x = displ, y = hwy, color = “blue”))
The position of the aes() is in the wrong position compared to the previous code. aes() is in geom_point and not ggplot().
What does the stroke aesthetic do? What shapes does it work with? (Hint: use ?geom_point)
ggplot(mpg, aes(x = displ, y = hwy, color = "pink")) +
geom_point(shape = 17, stroke = 5)
The stroke aesthetic bold the points making it bigger.
- What happens if you map an aesthetic to something other than a variable name, like aes(color = displ < 5)? Note, you’ll also need to specify x and y.
ggplot(mpg, aes(x = displ, y = hwy, color = displ <5)) +
geom_point(shape = 17)
It creates a boolean, true and false color scheme depending is displ is less than 5.