hadley / r4ds

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

Exercise 6 from 1.5.5 - Incorrect Code #1634

Closed Luaaalex closed 6 months ago

Luaaalex commented 9 months ago

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

davidrsch commented 6 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 6 months ago

Indeed @davidrsch's explanation is correct, thanks!