0

My x axis describes a timeline measured in years, with 50 years intervals. I want to set the starting year to 649 and the end year to 1258 and have them appear in the plot, and I try to use the scale_x_datetime function for this. I get an error message when I try to set the limits in that function.

Here is my code, built around the "tidslinje" dataframe:

                 gg_vistime(tidslinje,
                           linewidth = 5,
                           optimize_y = TRUE,
                           title = "Oversikt klassisk islamsk periode",
                           show_labels = TRUE,
                           background_lines = NULL) +
                           scale_x_datetime(date_breaks = "50 years",
                           date_labels = "%Y")

It produces this plot: gg_vistime plot, Islamic history timeline

This part of scale_x_datetime runs without problems:

scale_x_datetime(date_breaks = "50 years", date_labels = "%Y")

But the supposedly simple task of inserting a start year and an end year at either extremes of the x axis stumps me. Can I use scale_x_datetime for this? I have tried with the "limits" argument, but it tweaked the whole plot and didn't result in what I wanted.

jacobhoi
  • 35
  • 5
  • 1
    Your `limits` need to be date-times too. At the moment they are character strings representing years. And you have forgot to concatenate them into a vector. Try `limits = as.POSIXct(c("649-01-01", "1258-01-01"))`. Without seeing your actual data and the code you are using, this is just a guess. Please edit your question to make it reproducible. – Allan Cameron Feb 06 '23 at 22:12
  • 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 that can be used to test and verify possible solutions. – MrFlick Feb 06 '23 at 22:15
  • Thank you. The limits argument didn't work, unfortunately. I have tried to clarify with some more explanation and an image. – jacobhoi Feb 06 '23 at 22:34

0 Answers0