I have a time series where I would to visualise a percentage variabel and count variable. I would like the count plot to be bigger than the percentage plot. Putting the two plots together using ggpubr works, the problem is that x-axis does not align between the plots which makes it hard for a comparison. Any solution or workaround?
Example
library(tidyverse)
library(lubridate)
library(scales)
library(ggpubr)
df <- data.frame(date = rep(seq(ymd('2015-01-01'), ymd('2018-01-01'), by = '1 month'), 2),
percentage = c(runif(37, 0.6, 1), runif(37, 0.5, 0.9)),
count = c(runif(74, 1000000000, 2000000000)),
id = c(rep('A', 37), rep('B', 37)))
p1 <- ggplot(df, aes(x = date, y = percentage, col = id)) +
geom_line() +
scale_y_continuous(labels = percent)
p2 <- ggplot(df, aes(x = date, y = count, col = id)) +
geom_line() +
scale_y_continuous(labels = comma)
ggarrange(p1, p2, nrow = 2, common.legend = TRUE, legend = 'right', heights = c(4, 1))
