user11740857
user11740857

Reputation: 480

ggplot across multiple 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

Upvotes: 0

Views: 168

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389235

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')

Upvotes: 2

Related Questions