1

Hi I have done a plot where the x values is a string with the year and week value. ex. "2016-13"

This is an example of the code, here there is not overlapping because there is an small simple but in the real sample there is:

#install.packages("ggplot2")
library(ggplot2)

day_week<-c("2016-01","2016-02","2016-03","2017-01","2017-02","2017-40")
freq<-c(5,6,8,10,13,16)

x<-data.frame(day_week,freq)

ggplot(x, aes(x=day_week, y=freq))+ geom_bar(stat="identity")+ggtitle("plot")+xlab("weeks")+ylab("freq")

The problem is that when I do the plot the x lab appears all overlaped because there are many time labels. Is there any way I can put the year-week value every 4 weeks for example. Right now the year_week value is an string.

Thanks in advance, I am not managing to solve this !

Axeman
  • 32,068
  • 8
  • 81
  • 94
  • Converting to dates is your best bet, see the link from PoGibas. Also see [here](https://stackoverflow.com/questions/41724427/as-date-produces-unexpected-result-in-a-sequence-of-week-based-dates?noredirect=1&lq=1), since working with week numbers can be tricky. – Axeman Jul 27 '18 at 09:44

0 Answers0