how can we plot time with multiple groups in r?

Maybe try this aggregating your data:

library(tidyverse)
#Code
df %>% mutate(Date=as.Date(Date,'%d/%m/%Y'),
              Year=format(Date,'%Y')) %>%
  group_by(Year,Group) %>%
  summarise(N=n()) %>%
  ggplot(aes(x=factor(Year), y=Group, size = N,color=Group)) +
  geom_point(alpha=0.7)

Output:

enter image description here

Some data used:

#Data
df <- structure(list(Group = c("Group1", "Group1", "Group2", "Group3", 
"Group1", "Group1"), Date = c("29/12/2008", "29/12/2008", "29/12/2008", 
"10/05/2009", "10/05/2009", "10/05/2009")), class = "data.frame", row.names = c(NA, 
-6L))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top