Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

for the below data, can we plot ggplot across categories as shown below. Basically y axis is the count of customers across Months

df
Date    App Customers
Jan-01  A   Cust1
Feb-01  B   Cust2
Mar-01  A   Cust1
Apr-01  B   Cust2
May-01  C   Cust1

enter image description here

question from:https://stackoverflow.com/questions/66058026/ggplot-across-multiple-categories

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
192 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can count number of rows for each Month and App and plot the data.

library(dplyr)
library(ggplot2)

df %>%
  count(Date, App) %>%
  mutate(Date = as.Date(paste0(Date, '-01'), '%b-%y-%d')) %>%
  ggplot(aes(Date, n, color = App)) + 
  geom_line() + 
  scale_x_date(date_labels = '%b %Y')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...