如何抑制#>由拼凑而成的plot_layout()

时间:2018-08-24 20:41:57

标签: r ggplot2

我正在运行代码,以使用plot_layout库中的patchwork函数,发现对于某些绘图,plot_layout创建了组合绘图视图,但还显示了以{为前缀的消息{1}}。如何从R markdown文件中删除这些消息?我可以使用大块选项吗?

这是我的代表:

#>

```

``` r{corr-plots}
library(ggplot2)
library(MASS)
library(patchwork)
set.seed(123)

cor_100 <- as.data.frame(mvrnorm(100, mu = c(0,0), 
                 Sigma = matrix(c(1 ,1, 1, 1), ncol = 2), 
                 empirical = TRUE))

cor_70 <- as.data.frame(mvrnorm(100, mu = c(0,0), 
                 Sigma = matrix(c(1,0.7,0.7,1), ncol = 2), 
                 empirical = TRUE))

cor_100_plot <- ggplot(cor_100, aes(V1, V2)) + geom_point() + 
  labs(title = "Correlation = 1", y = "y", x = "x") + 
  geom_hline(yintercept = mean(cor_100$V2), lty = 2) + 
  geom_vline(xintercept = mean(cor_100$V1), lty = 2) + 
  theme_minimal(base_size = 15) 

cor_70_plot <- ggplot(cor_70, aes(V1, V2)) + geom_point() + 
  labs(title = "Correlation = 0.7", y = "y", x = "x") + 
  geom_hline(yintercept = mean(cor_70$V2), lty = 2) + 
  geom_vline(xintercept = mean(cor_70$V1), lty = 2) + 
  theme_minimal(base_size = 15)

plot_layout(cor_100_plot + cor_70_plot)

reprex package(v0.2.0)于2018-08-24创建。

1 个答案:

答案 0 :(得分:0)

Thomas Lin Pedersen在Twitter上回答了我。我的plot_layout()语法错误。它应该是cor_100_plot + cor_70_plot + plot_layout()