hadley / r4ds

R for data science: a book
http://r4ds.hadley.nz
Other
4.51k stars 4.19k forks source link

Exercise 6 from 1.5.5 - Incorrect Code #1634

Closed Luaaalex closed 3 months ago

Luaaalex commented 6 months ago

See that the code offered is already correct. The code did not repet the color = specie, shape = specie.

davidrsch commented 3 months ago

Hello @Luaaalex I believe the intention behind the exercise was to firstly execute the suggested code:

ggplot(
  data = penguins,
  mapping = aes(
    x = bill_length_mm, y = bill_depth_mm, 
    color = species, shape = species
  )
) +
  geom_point() +
  labs(color = "Species")

Obtaining the following output: image

Which indeed have two legends as stated in the exercise and then correct it:

ggplot(
  data = penguins,
  mapping = aes(
    x = bill_length_mm, y = bill_depth_mm, 
    color = species, shape = species
  )
) +
  geom_point()

image

mine-cetinkaya-rundel commented 3 months ago

Indeed @davidrsch's explanation is correct, thanks!