在 R 中使用 cowplot 对齐 image() 图
Use cowplot in R to align image() plots
我想对齐 R 中使用 image()
函数生成的两个图。
示例代码:
# Load package
library(cowplot)
# Plot sample image
image <- image(matrix(rnorm(1000), 100,100))
# Align plots
plot_grid(image, image)
但是,当我这样做时,情节并没有出现。我错过了什么吗?或者 cowplot 不能处理图像函数生成的图吗?
您需要做一些工作来将这些存储在您的环境中。如果您检查 image
,您会看到它是 NULL
。所以你必须记录它,然后绘制它。
p <- recordPlot()
plot.new()
image(matrix(rnorm(1000), 100,100))
p
plot_grid(p, p, nrow = 2)
如果您想将 cowplot 用于 base-R 图,我强烈建议您使用 cowplot 的当前开发版本。在该版本中,您只需将您的图像代码转换为公式(通过在前面添加 ~
)即可。
library(cowplot)
#>
#>
#> *******************************************************
#> Note: cowplot does not change the default ggplot2 theme
#> anymore. To recover the previous behavior, execute:
#> theme_set(theme_cowplot())
#> *******************************************************
# Plot sample image
image <- ~image(matrix(rnorm(1000), 100,100))
# Align plots
plot_grid(image, image)
由 reprex package (v0.2.1)
创建于 2018-10-27
我想对齐 R 中使用 image()
函数生成的两个图。
示例代码:
# Load package
library(cowplot)
# Plot sample image
image <- image(matrix(rnorm(1000), 100,100))
# Align plots
plot_grid(image, image)
但是,当我这样做时,情节并没有出现。我错过了什么吗?或者 cowplot 不能处理图像函数生成的图吗?
您需要做一些工作来将这些存储在您的环境中。如果您检查 image
,您会看到它是 NULL
。所以你必须记录它,然后绘制它。
p <- recordPlot()
plot.new()
image(matrix(rnorm(1000), 100,100))
p
plot_grid(p, p, nrow = 2)
如果您想将 cowplot 用于 base-R 图,我强烈建议您使用 cowplot 的当前开发版本。在该版本中,您只需将您的图像代码转换为公式(通过在前面添加 ~
)即可。
library(cowplot)
#>
#>
#> *******************************************************
#> Note: cowplot does not change the default ggplot2 theme
#> anymore. To recover the previous behavior, execute:
#> theme_set(theme_cowplot())
#> *******************************************************
# Plot sample image
image <- ~image(matrix(rnorm(1000), 100,100))
# Align plots
plot_grid(image, image)
由 reprex package (v0.2.1)
创建于 2018-10-27