How do i reshape my data from y-m-d into years?

57 Views Asked by At

I want to plot a frequency of topics over years. However my variable containing dates have the following structure, example:2016-01-01. This means that the data is structured in days. However i want the data to be visualized on a monthly basis.

The data is structured in a data.frame

I tried to visualize my topic frequency over the dates as such:

  ggplot(data = dat,
       aes(x = date,
           fill = Topics[1])) +
  geom_freqpoly(binwidth = 30)

However when i execute the command my visualization only shows every third month, like: January, April, July, etc..

How do I get the dates on the x-axis to show all the months: (January, Februrary, March, April .. etc)?

1

There are 1 best solutions below

3
On

You can edit your x axis labels

library(tidyverse)
library(lubridate)

last_month <- Sys.Date() - 0:199
df <- data.frame(
  date = last_month,
  price = runif(200)
)
base <- ggplot(df, aes(date, price)) +
  geom_line()

base + scale_x_date(date_breaks = "months", date_labels="%B")