0

I am creating a series of plots like so:

data_subset <- df_order

#Hier wird eine Spalte hinzugefügt die sich nur auf das Jahr bezieht, damit werden die Daten dann auf der X-Achse abgebildet
data_subset$Year <- format(data_subset$DateAsDate, "%Y")
plotdf <- ddply(data_subset,.(Year, Sex),
      function(zz){
        #Sämtliche Daten hier werden pro Jahr und Geschlecht aufgetragen.
        data.frame(
          rownum=nrow(zz)
          )
        }
      )

library(reshape2) 
library(reshape)

meltdf <- melt(plotdf, id=c("Year", "Sex"))

meltdf$Dicipline <- substr(meltdf$variable, 1, nchar(as.character(meltdf$variable))-3)
meltdf$variable <- substr(meltdf$variable, nchar(as.character(meltdf$variable))-2, nchar(as.character(meltdf$variable)))

meltdf %>% ggplot(aes(x = Year, y = value, colour = variable, group = variable)) + 
  geom_line() + facet_grid(Sex~Dicipline) + labs(x="Jahr", y="Anzahl Teilnahmen")
  
  
  
#ggplot(plotdf, aes(x = Year)) + geom_line(aes(y = xmin)) + geom_line(aes(y = xmed)) + labs(x="Jahr", y="Gewichtswerte")

It plots the number of values of my data frame per year separated by Sex, and it works fine, but the x-Axis looks very crammed, since I have data from the 1960s until today.

enter image description here

How can I reduce the number of labels on the x-Axis, so that e.g. only every 10th year is printed below the axis?

monamona
  • 1,195
  • 2
  • 17
  • 43
  • 3
    Looks as if your `Year` variable is a character. Check that and try with converting to a numeric, e.g. use `aes(x=as.numeric(Year), ...)`. – stefan Jan 12 '23 at 18:55
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 12 '23 at 19:03
  • @stefan That was it! Thanks a lot. If you want to convert your comment into a short answer I can accept it so others can see better in the future! – monamona Jan 12 '23 at 19:11

0 Answers0