使用R中的cowplot来对齐image()绘图

3
我想要在 R 中对两个使用 image() 函数生成的图进行对齐。
代码示例:
# Load package
library(cowplot)

# Plot sample image
image <- image(matrix(rnorm(1000), 100,100))

# Align plots
plot_grid(image, image)

然而,当我这样做时,图形并没有出现。我错过了什么吗?或者cowplot不能处理由image函数生成的图形吗?
2个回答

2

您需要做一些工作来存储它们在您的环境中。如果您检查image,您会发现它是NULL。因此,您需要记录它,然后绘制它。

p <- recordPlot()
plot.new()
image(matrix(rnorm(1000), 100,100))
p

plot_grid(p, p, nrow = 2)

enter image description here


1
如果您想在基本R图中使用cowplot,我强烈建议使用当前的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)

2018年10月27日由reprex包 (v0.2.1)创建


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接