R FOR DATA SCIENCE. Page 61-62. Exercise 3

install.packages("ggplot2")
library(ggplot2)
library(tidyverse)
mpg
view(mpg)
glimpse(mpg)
#>Ex. 3: In the scatterplot of hwy versus displ, what happens if you map a third variable to linewidth?
ggplot(mpg, aes(x = hwy, y = displ)) +
geom_density(linewidth = 0.75)

Console:
" ggplot(mpg, aes(x = hwy, y = displ)) +

  • geom_density(linewidth = 0.75)
    Error in geom_density():
    ! Problem while setting up geom.
    :information_source: Error occurred in the 1st layer.
    Caused by error in compute_geom_1():
    ! geom_density() requires the following missing aesthetics: y
    Run rlang::last_trace() to see where the error occurred.
    Warning message:
    The following aesthetics were dropped during statistical transformation: y
    :information_source: This can happen when ggplot fails to infer the correct grouping structure in the data.
    :information_source: Did you forget to specify a group aesthetic or to convert a numerical variable into a factor? "

¿Problem, hmmm...?

Is the exercise in here somewhere ? there arent page numbers for me to refer to...
https://r4ds.hadley.nz/

1 Like

Voilà! I had already entered that page but I had not stopped to read the menu on the left :man_facepalming: :sweat_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.