How can I reduce the number of breaks or ticks on the x axis of my time series?

Automatically the graph uses breaks every data (every hour) and the x-axis is saturated with information.

These are the lines I use for the code and I attach an image of the plot:

plotObj <- ggplot(prueba1, aes(x=V1, y=V2, group = 1)) + geom_line()
plotly::ggplotly(plotObj)

I hope someone can help me, I would appreciate it.

Best regards!

That is probably happening because your V1 column is characters and not numeric dates. What is the result of

class(prueba1$V1)

If it is "character", you can convert the column to dates or timestamps using functions from the lubridate package. What is the format of your dates?

The column is dates and the format is DD/MM/YYYY HH:MM

Thank you!!

Please post the output of

dput(head(prueba1, 30))

Put a line with three back ticks just before and after the pasted output, like this:

```
Output of dput() function goes here
```

When I put the output, it throws me an error

"01/01/2022 02:00", "01/01/2022 03:00", "01/01/2022 04:00", "01/01/2022 05:00", 
"01/01/2022 06:00", "01/01/2022 07:00", "01/01/2022 08:00", "01/01/2022 09:00", 
"01/01/2022 10:00", "01/01/2022 11:00", "01/01/2022 12:00", "01/01/2022 13:00", 
"01/01/2022 14:00", "01/01/2022 15:00", "01/01/2022 16:00", "01/01/2022 17:00", 
"01/01/2022 18:00", "01/01/2022 19:00", "01/01/2022 20:00", "01/01/2022 21:00", 
"01/01/2022 22:00", "01/01/2022 23:00", "02/01/2022 00:00", "02/01/2022 01:00", 
"02/01/2022 02:00", "02/01/2022 03:00", "02/01/2022 04:00", "02/01/2022 05:00"
), V2 = c(0.644, 0.554, 0.543, 0.642, 0.669, 0.695, 0.715, 0.724, 
0.715, 0.691, 0.513, 0.205, -0.11, -0.371, -0.589, -0.701, -0.701, 
-0.585, -0.419, -0.221, 0.027, 0.266, 0.445, 0.573, 0.622, 0.632, 
0.602, 0.569, 0.598, 0.595), V3 = c(0.644, 0.554, 0.543, 0.642, 
0.669, 0.695, 0.715, 0.724, 0.715, 0.691, 0.513, 0.205, -0.11, 
-0.371, -0.589, -0.701, -0.701, -0.585, -0.419, -0.221, 0.027, 
0.266, 0.445, 0.573, 0.622, 0.632, 0.602, 0.569, 0.598, 0.595
)), row.names = c(NA, 30L), class = "data.frame")

Error: attempt to use zero-length variable name

When I put the output, it throws me an error

structure(list(V1 = c("01/01/2022 00:00", "01/01/2022 01:00", 
"01/01/2022 02:00", "01/01/2022 03:00", "01/01/2022 04:00", "01/01/2022 05:00", 
"01/01/2022 06:00", "01/01/2022 07:00", "01/01/2022 08:00", "01/01/2022 09:00", 
"01/01/2022 10:00", "01/01/2022 11:00", "01/01/2022 12:00", "01/01/2022 13:00", 
"01/01/2022 14:00", "01/01/2022 15:00", "01/01/2022 16:00", "01/01/2022 17:00", 
"01/01/2022 18:00", "01/01/2022 19:00", "01/01/2022 20:00", "01/01/2022 21:00", 
"01/01/2022 22:00", "01/01/2022 23:00", "02/01/2022 00:00", "02/01/2022 01:00", 
"02/01/2022 02:00", "02/01/2022 03:00", "02/01/2022 04:00", "02/01/2022 05:00"
), V2 = c(0.644, 0.554, 0.543, 0.642, 0.669, 0.695, 0.715, 0.724, 
0.715, 0.691, 0.513, 0.205, -0.11, -0.371, -0.589, -0.701, -0.701, 
-0.585, -0.419, -0.221, 0.027, 0.266, 0.445, 0.573, 0.622, 0.632, 
0.602, 0.569, 0.598, 0.595), V3 = c(0.644, 0.554, 0.543, 0.642, 
0.669, 0.695, 0.715, 0.724, 0.715, 0.691, 0.513, 0.205, -0.11, 
-0.371, -0.589, -0.701, -0.701, -0.585, -0.419, -0.221, 0.027, 
0.266, 0.445, 0.573, 0.622, 0.632, 0.602, 0.569, 0.598, 0.595
)), row.names = c(NA, 30L), class = "data.frame")

Error: attempt to use zero-length variable name

Hi @krv , remember put a reproducible example.

for reprex

Maybe this library could help you in scale of plot:

Something like this would work.

library(tidyverse)
library(lubridate)

# new dataset
prueba2 <- prueba1 %>% 
  mutate(V1 = as_datetime(V1))

ggplot(prueba2, aes(V1, V2)) +
  geom_line()

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.