R 在绘图打印输出时抑制行号
R supress line numbers on plot printout
我正在使用以下代码生成一系列图表。不幸的是,当你编织这个 RMD 文件时,行号出现在每个图表之前。
---
title: "Test"
author: "John"
date: "September 10, 2015"
output: pdf_document
---
```{r, echo=FALSE, warning=FALSE, message=FALSE}
library(dplyr)
library(ggplot2)
makePlots <- function(groupedTable, grouping){
ggplot(groupedTable) +
geom_bar(aes(disp), binwidth = 20) +
ggtitle(grouping)
}
allPlots <- mtcars %>% group_by(cyl) %>% do(plots = makePlots(.,unique(.$cyl)))
allPlots$plots
```
产生这个输出:
在截图中,你会看到
## [[1]]
和
##
## [[2]]
我只想有图表而没有那些。
有什么想法吗?
您可以在 for 循环中打印它们而不是打印列表:
for (p in allPlots$plots) {
print(p)
}
另一种方法是使用 grid.arrange
将这些图合并为一个,如图 here 所示。这还允许您选择将图表组织成多少行 and/or 列。
library(gridExtra)
args <- c(allPlots$plots, ncol = 1)
do.call(grid.arrange, args)
我正在使用以下代码生成一系列图表。不幸的是,当你编织这个 RMD 文件时,行号出现在每个图表之前。
---
title: "Test"
author: "John"
date: "September 10, 2015"
output: pdf_document
---
```{r, echo=FALSE, warning=FALSE, message=FALSE}
library(dplyr)
library(ggplot2)
makePlots <- function(groupedTable, grouping){
ggplot(groupedTable) +
geom_bar(aes(disp), binwidth = 20) +
ggtitle(grouping)
}
allPlots <- mtcars %>% group_by(cyl) %>% do(plots = makePlots(.,unique(.$cyl)))
allPlots$plots
```
产生这个输出:
在截图中,你会看到
## [[1]]
和
##
## [[2]]
我只想有图表而没有那些。 有什么想法吗?
您可以在 for 循环中打印它们而不是打印列表:
for (p in allPlots$plots) {
print(p)
}
另一种方法是使用 grid.arrange
将这些图合并为一个,如图 here 所示。这还允许您选择将图表组织成多少行 and/or 列。
library(gridExtra)
args <- c(allPlots$plots, ncol = 1)
do.call(grid.arrange, args)