Facetting continuous variable

Hello,

Is there a way to more directly facet by a continuous variable, in such a way that a line would continue across each of the facets? I specify "directly" because I realize this could be accomplished by creating a "category" variable, but is there a way to do this without such a categorical variable?

For example, for the 52 weeks of the year, create facets thusly:

First row: weeks 1-12
Second row: weeks 13-26
etc.
etc.

  • ice

You should be able to obtain that using something along the lines of:

# Load libraries ----------------------------------------------------------
library("tidyverse")
library("lubridate")


# Create example data -----------------------------------------------------
set.seed(8511)
my_data <- tibble(
  date = seq(from = dmy("01-01-2020"),
             to = dmy("31-12-2020"),
             by = "days"),
  week = week(date),
  value = runif(length(date))
)


# Visualise ---------------------------------------------------------------
my_data %>% 
  ggplot(aes(x = date,
             y = value)) +
  geom_line() +
  facet_wrap(vars(week),
             ncol = 12,
             scales = "free_x")

Yielding:


Hope it helps! :slightly_smiling_face: