-1

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

  • We don't have any of your data, so we can't run your code, and we can't see any of your output, and you're using notation that may or may not make sense (is `Topics` something that would make sense to subset in this way?). The title and description don't match either, so all anybody can do is guess. – camille Dec 20 '19 at 15:37

1 Answers1

0

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")
Bruno
  • 4,109
  • 1
  • 9
  • 27
  • Sorry but i don't understand the answer. The dates worked (kind of). The results were "01" "02" etc. on the x axis. But i need to transform them into "January" "February" etc. I tried labelling them like this base + scale_x_date(date_breaks = "1 month", date_labels="January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") That didn't work either. – Gustav Skov Dec 20 '19 at 14:38
  • Sorry I forget that sometimes people are still not familiar with documentation, it is fine when we are starting to code you will improve keep on trying! I changed it to solve your specific case here is a cool blog post that could help https://www.r-bloggers.com/customizing-time-and-date-scales-in-ggplot2/ – Bruno Dec 20 '19 at 14:44
  • Thanks! That helped. However should i specify the number of observations in the runif function? – Gustav Skov Dec 20 '19 at 15:41