I am learning R4DS,an example confused me,these two codes below show quite differently, I tried to make a new variable through mutate(),color1 = fct_rev(color),color1 has the same value as color has.
diamonds %>%
ggplot(aes(x = color, y = price)) +
geom_boxplot()
your example doesnt show a mutate to make color1, it shows you redefine color.
And your example works, in so far as when I compare the two boxplots the axis color labels are in reverse order from each other.... so is there really an issue ?
I just curious how the fct_rev works,because in the second example,after using the fct_rev,the raw data (diamonds) does not change.so why the boxplot change the sequence
the raw data will never change without an assignment on diamonds.
without a diamonds = , or diamonds <- or diamonds %<>% diamonds will not change
the pipe %>% simply passes diamonds into other functions that then give outputs, i.e. you are mutating a temporary representation that is lost after you plot it
try