Plotting Multiple Years Worth of Data

Hi there, I am new to R and I feel like I have searched the entire internet for an answer. I apologize if this is an easy solution. I have 23,000 acoustic telemetry data points over 15 years (2006-2019). I am trying to create an abacus-type graph to determine the seasonal cycles of migration. Obviously, 15 years of dates will not fit onto the x-axis - is there a way to split the data into years and create a separate graph for each year? I want 'code' on y-axis and 'PT_Time_Date_Only' on x-axis.


initial_data <- data.frame(
  fulldate = seq.Date(
    from = as.Date("2010-01-01"),
    by = "month",
    length.out = 84
  ),
  code = 620 + cumsum(sample(c(-1, 1), 84, TRUE))
)

library(tidyverse)
library(lubridate)

prepared_data <- initial_data %>% mutate(
  yearpart = year(fulldate),
  months_common_year = ymd(2010 * 10000 + 100 * month(fulldate) + day(fulldate))
)

ggplot(
  data = prepared_data,
  mapping = aes(
    x = months_common_year,
    y = code
  )
) +
  facet_wrap(~yearpart, ncol = 1) +
  geom_line() +
  scale_x_date(date_labels = "%b", date_breaks = "1 month")

1 Like

Thank you! If I were to want to use ggplotly to create an interactive plot for each individual year, would you have any advice? I have figured out how to create a plotly for all years stacked on top of one another, but am trying to have 14 different plotlys for each year.

the ggplot chart above can be piped to ggplotly function to convert it to a plotly

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