从 ggplot 对象中提取面板大小
Extract panel size from ggplot object
我尝试从 ggplot
对象中提取面板的宽度和高度。到目前为止我做了什么:
library(ggplot2)
library(gtable)
# Create object
p <- ggplot(iris, aes(x = Sepal.Length)) +
geom_histogram()
# Convert the plot to a grob
gt <- ggplotGrob(p)
# Extract panel
panel <- gtable_filter(gt, "panel")
现在我忙于提取正确的尺寸。知道如何进行吗?
panel$widths
将 return 1null
。这是 ggplot2 的一个特性:面板的大小使其能够扩展以填充视口上可用的 space。
我尝试从 ggplot
对象中提取面板的宽度和高度。到目前为止我做了什么:
library(ggplot2)
library(gtable)
# Create object
p <- ggplot(iris, aes(x = Sepal.Length)) +
geom_histogram()
# Convert the plot to a grob
gt <- ggplotGrob(p)
# Extract panel
panel <- gtable_filter(gt, "panel")
现在我忙于提取正确的尺寸。知道如何进行吗?
panel$widths
将 return 1null
。这是 ggplot2 的一个特性:面板的大小使其能够扩展以填充视口上可用的 space。