nan.xiao ggplot2 responsive panels with shiny and facet_wrap()
我纯属小跑个题:
if (width >= 1140) p <- p + facet_wrap(vars(class), ncol = 4)
if (width >= 960 & width < 1140) p <- p + facet_wrap(vars(class), ncol = 2)
if (width < 960) p <- p + facet_wrap(vars(class), ncol = 1)
为了少重复几次代码,我一般用这种鬼都看不懂的火星写法:
i <- (width >= 960) + (width >= 1140) + 1
p <- p + facet_wrap(vars(class), ncol = c(1, 2, 4)[i])
要是断点太多的话,就上 findInterval()
了。