scale_date()
set of functions accept scale position on top or bottom (for horizontal scales) OR right or left (for vertical scales). However it lacks scale_continuous(sec.axis)
which allows for secondary axis (say to put time range both at top and bottom).
Here is the code producing dates just at bottom of the chart:
library(data.table)
library(ggplot2)
set.seed(123)
foo <- data.table(day = rep(seq(as.Date("2018-01-01"), as.Date("2018-01-30"), by="days"), 3),
var = c(rep("v1", 30), rep("v2", 30), rep("v3", 30)),
value = round(rnorm(90)*90))
ggplot2::ggplot(data = foo, ggplot2::aes(x = day, y = value, color = var)) +
ggplot2::geom_line() +
ggplot2::ggtitle("Demo example",
subtitle = "random values") +
ggplot2::scale_x_date(date_labels = "%Y%m%d",
breaks = seq(from = min(foo$day), to = max(foo$day), length.out = 5),
position = "bottom") +
ggplot2::facet_grid(var ~ ., scales = "free") +
ggplot2::theme(legend.position = "top",
legend.title = ggplot2::element_blank(),
legend.direction = "horizontal",
plot.title = ggplot2::element_text(hjust = 0.5),
plot.subtitle = ggplot2::element_text(hjust = 0.5))
Output as is follows:
I have many time series graphs which I am plotting in stacked way. This make the scroll necessary for a user to see time scale (not good UX). So I want to have time scale both at top and bottom. How can I achieve this?