下面是代码和图表。
该图具有三个方面。在哪里the_plot
我能发现它有三个方面吗?是的,我可以从 mtcars
得到它数据框,或 the_plot$data
,但我不想重新创建数据分析。相反,我想检查 the_plot
的图形元素,所以我不必在多个地方复制应用程序逻辑。 the_plot$facet
没有显示任何我认识的东西,其他绘图变量也没有显示。
我正在使用 tidyverse 1.3.0。
library(tidyverse)
data(mtcars)
the_plot<-ggplot(mtcars, aes(mpg, disp, group=cyl)) + facet_wrap(~cyl) + geom_point()
the_plot
最佳答案
您可以使用 gg_build() 函数访问 ggplot 数据
out <- ggplot_build(the_plot)
length(levels(out$data[[1]]$PANEL))
[1] 3
关于r - 如何以编程方式告诉 ggplot 有多少个方面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61346939/