I\'am stuck with the following problem:
I want to display different characteristics of a timeseries in one plot (with multiple subplots). To align the chart areas an
You can change the grobs
of your plot to do this
library(ggplot2)
library(grid)
library(scales)
#plot
p <- ggplot(df_melt, aes(x=date, y=value)) +
geom_line() +
facet_grid(variable~., scales = "free")
# change facet heights
g1 <- ggplotGrob(p)
g1$heights[[3]] <- unit(2, "null")
# change labels - create second plot with percentage labels (nonsese % here)
p2 <- ggplot(df_melt, aes(x=date, y=value)) +
geom_line() +
facet_grid(variable~., scales = "free") +
scale_y_continuous(labels = percent_format())
g2 <- ggplotGrob(p2)
#Tweak axis - overwrite one facet
g1[["grobs"]][[2]] <- g2[["grobs"]][[2]]
grid.newpage()
grid.draw(g1)