2
下面給出gg
對象或gg_b
對象,是否有可能爲每個軸檢測映射到軸上的變量是否是離散的?給定一個ggplot2對象,我可以檢測軸是否離散?
library(ggplot2)
library(dplyr)
gg <-
mtcars %>%
ggplot(aes(factor(cyl), hp)) +
geom_point()
gg_b <- ggplot_build(gg)
我希望能夠做到這一點,以支持圖形上的組織風格。
SOLUTION(HT /巴蒂斯特)
has_discrete_axis <-
function(gg) {
gg_b <- ggplot2::ggplot_build(gg)
lapply(gg_b$layout$panel_scales,
function(s) inherits(s[[1]], "ScaleDiscrete"))
}
謝謝......我在$數據和$情節向四周看了看,但沒有看到任何證據除標籤外的特殊因素。 –