Skip to content

transition_reveal + geom_text assume ordered column to work #323

@osiris08

Description

@osiris08

In order to reveal lines with correct geom_text label, transition_reveal needs the table to be ordered to work. In the following example, I shuffled the data, and it cannot show labels correctly.

It's very often data comes in with shuffled order, and it's difficult to know this assumption.

airq <- airquality %>% dplyr::sample_n(153)
airq$Month <- format(ISOdate(2004,1:12,1),"%B")[airq$Month]
ggplot(airq, aes(Day, Temp, group = Month)) + 
  geom_line() + 
  geom_segment(aes(xend = 31, yend = Temp), linetype = 2, colour = 'grey') + 
  geom_point(size = 2) + 
  geom_text(aes(x = 31.1, label = Month), hjust = 0) + 
  transition_reveal(Day) + 
  coord_cartesian(clip = 'off') + 
  labs(title = 'Temperature in New York', y = 'Temperature (°F)') + 
  theme_minimal() + 
  theme(plot.margin = margin(5.5, 40, 5.5, 5.5))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions