Consider a faceted ggplot
plotdf <- data.frame(x = 1:21,
y = 3*(1:21)+4,
z = c(rep(1,3), rep(2,3), rep(3,3), rep(4
Following up on @Aditya's answer, this is (as of ggplot 3.1.1):
library(magrittr)
gg_facet_nrow_ng <- function(p){
assertive.types::assert_is_any_of(p, 'ggplot')
p %>%
ggplot2::ggplot_build() %>%
magrittr::extract2('layout') %>%
magrittr::extract2('layout') %>%
magrittr::extract2('ROW') %>%
unique() %>%
length()
}