user6644063 user6644063 - 1 month ago 6
R Question

plot count of events against months from large dataset

I need to create a plot showing the count of events (y-axis) against months (x-axis), without considering the year the events occurred.

My data are stored into a

data.frame
and I have got a column
Date
showing the year-month-day of the event as follows:

df = read.table(text = 'ID Date
1 1975-10-01
1 1975-10-04
2 1975-11-03
2 1976-01-17
2 1980-02-04
3 1980-05-11
4 1983-03-09
4 1983-04-10', header = TRUE)


My real data.frame contains more observations but I hope that my data sample will be enough to solve my question.

Any suggestion?

Thanks for anyone who will help me.

Answer
df$month <- factor(lubridate::month(df$Date), 1:12, month.name)

library(ggplot2)
ggplot(df, aes(month)) + geom_bar() + xlim(month.name)

enter image description here

Comments