0

I am trying to display data over some years and my labels on the x axis overlap each other. overlapping data

I generate the plot as follows

plotData<-subset(myData,myData$category=="value")

test <- ggplot(plotData, aes(x=date, y=value, group=name))
test + geom_line(aes(color=name))

if I add

 + theme(axis.text.x  = element_text(angle=45))

it is slightly better, but still very crowded.

rotated still overlapping data

Is there any option to specify how many labels there should be per axis, or an option just to display every 10th label?

Tidoni
  • 195
  • 1
  • 4
  • 13
  • Personally I also usetheme_set(theme_classic()), might add some visibility to your graphs. – Bart Jul 25 '19 at 11:36

1 Answers1

2

You can use scale_x_date() with the date_breaks argument. An example with some dummy data:

df <- data.frame(x = seq.Date(as.Date("2000-01-01"), by = 1, length.out = 1000), y = rep(1:10, each = 100))

df %>%
  ggplot() +
  geom_line(aes(x, y)) +
  scale_x_date(date_breaks = "26 weeks")

enter image description here

Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56