I am using time series data (several months with stamps in the range of seconds). However, for a reproduceable example here, I used smaller but similar data from the NAB Corpus (Number of twitter posts regarding the Apple stock over time)
# packages
library(readr)
library(magrittr)
library(scales)
library(ggplot2)
# data
twttr_aapl <- "https://raw.githubusercontent.com/numenta/NAB/master/data/realTweets/Twitter_volume_AAPL.csv"
twttr_aapl_ts <- read_csv(twttr_aapl,
col_types = cols(timestamp = col_datetime(format = "%Y-%m-%d %H:%M:%S"),
value = col_integer()))
I really like to use the ggforce package to highlight patterns in the data by zooming in via facet_zoom; e.g., before an anomaly appears. The result is two plots on top of each other that look something like this:
twttr_aapl_ts %>% ggplot(aes(x = timestamp, y = value)) +
geom_line() +
scale_x_datetime("time",
# date_breaks = "hour",
# position = "top",
labels = scales::label_date_short(),
breaks = breaks_pretty()) +
scale_y_continuous(expression("log"[10]*"(# tweets)"),
trans = "log10",
breaks = breaks_log()) +
ggforce::facet_zoom(xlim = c(as.POSIXct("2015-03-14 22:00:00"),
as.POSIXct("2015-03-18 18:00:00")),
horizontal = FALSE) +
theme_bw() -> twttr_plt_01

Is it possible to access only one of the plots or at least its axis? I’d like to
- change the x-axis position of the upper plot only ("top"), so that it no longer intersects with the zoom lines, i.e., the axis position of the lower plot should remain the same (bottom). However, applying
position = "top"changes the position of both of the two x-axis. - change the breaks so that hours are displayed in the bottom plot. But using
date_breaks = "hour"also changes the breaks for both axes. - scale the y-axis of the upper plot, only (e.g. to
trans = "log10") but not the one of the lower plot. - change the way the labels are displayed (in the given example, only day and time are relevant in the bottom plot, month and year are redundant).
So, my question is not only related to scales rather it is a general one. E.g., if I want to change only the line color in the lower plot, only.