-2

I have included the data and code needed to reproduce my current results. I have a single graph for different individuals (4), and they are data collected in different years. I currently have the x-axis as Julian Dates, so it shows the dates for each year.

I would like to get it to show the x-axis only from 0-365 once, instead of repeating it for multiple years. Is there a good way to accomplish this? I think essentially what I'm asking is if it is possible to condense these four lines into a single graph with the same x-axis and y-axis?

library(ggforce)
library(dplyr)
library(lubridate)

df <- read.csv("https://raw.githubusercontent.com/jhnhng/Data/main/NSD_Figure.csv")
df$t2  <- as.POSIXct(df$t2)

ggplot(ind_steps, aes(x = t2, y = NSD)) +
  labs(x = "Julian Date", y = "Net Squared Displacement") +
  geom_line() + theme_bw() +
  theme(axis.text.x = element_text(angle = 90)) +
  scale_x_datetime(date_breaks = '10 days', date_labels = '%j') +
  facet_wrap(~class, ncol = 1 , nrow = 4)
John Huang
  • 845
  • 4
  • 15
  • 1
    Keep in mind the *minimal* part of [mcve]. You have 36 lines of code for prepping data versus 6 lines for plotting, which is what the question is actually about—just include an [workable sample](https://stackoverflow.com/q/5963269/5325862) of `ind_steps`. You're also loading packages & adding code that aren't necessary to the question itself (`sf` doesn't seem to be used, and if facetting is relevant to the question, `facet_wrap` instead of `facet_wrap_paginate` should suffice). Narrowing the scope of the question helps you debug and helps us follow what the issue actually is – camille Dec 18 '21 at 23:38

1 Answers1

1
df$t3 <- as.numeric(format(df$t2, "%j"))

then

ggplot(df, aes(x = t3, y = NSD)) +
  ...
  scale_x_continuous(breaks = scales::breaks_width(10)) +
  ...

enter image description here

Jon Spring
  • 55,165
  • 4
  • 35
  • 53