默认情况下不适合幻灯片,甚至不通过任何其他方式打印.

这是答案.Rmd:Edit: it seems you have to use plot() in every chunk. Second plot now prints.

# Plot should show at high resolution

```{r echo=FALSE, comment = ""}
# load some data
require(plyr)
rbi <- ddply(baseball, .(year), summarise,  
  mean_rbi = mean(rbi, na.rm = TRUE))
```

```{r}
# plot
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Second attempt
```{r, fig.width = 2, fig.height = 2}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Third attempt
```{r, out.width = 2, out.height = 2}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Fourth attempt
```{r, out.width = '200px', out.height = '200px'}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Fifth attempt
```{r, out.width = '\\maxwidth'}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

留到test.Rmd

knit("test.Rmd")
system("pandoc -s -t beamer --slide-level 1 test.md -o test.tex")

在RStudio中打开test.tex,然后单击"编译PDF".

我读过易慧的documentation本书,希望我没有错过一些非常明显的东西.

Edit个新代码,包含了易慧的建议.

```{r setup, include=FALSE}
opts_chunk$set(dev = 'pdf')
```

# Plot should show at high resolution

```{r echo=FALSE, comment = ""}
# load some data
require(plyr)
rbi <- ddply(baseball, .(year), summarise,  
  mean_rbi = mean(rbi, na.rm = TRUE))
```

```{r}
# plot
plot(mean_rbi ~ year, type = "l", data = rbi)
```

# Second attempt
```{r, fig.width = 4, fig.height = 4}
plot(mean_rbi ~ year, type = "l", data = rbi)
```

sessionInfo()

 R version 3.0.1 (16/05/2013)
Platform: x86_64-pc-linux-gnu (64-bit)

Local:
 [1] LC_CTYPE = en_US.UTF-8 LC_NUMERIC = C LC_TIME = C LC_COLLATE = C        
 [5] LC_MONETARY=C        LC_MESSAGES=C        LC_PAPER=C           LC_NAME=C           
 [9] LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plyr_1.8       markdown_0.6   knitr_1.2      rCharts_0.3.51 slidify_0.3.52

loaded via a namespace (and not attached):
 [1] RJSONIO_1.0-3   codetools_0.2-8 digest_0.6.3    evaluate_0.4.3  formatR_0.8    
 [6] grid_3.0.1      lattice_0.20-15 stringr_0.6.2   tools_3.0.1     whisker_0.3-2  
[11] yaml_2.1.7  

推荐答案

我认为这是一个经常被问到的关于潘多克和markdown制作的beamer幻灯片中人物行为的问题.真正的问题是,R Markdown默认生成PNG图像(从knitr开始),默认情况下很难在LaTeX中获得正确的PNG图像大小(我不知道为什么).然而,要获得正确的PDF图像大小是相当容易的.一种解决方案是在第一个区块中将默认图形设备重置为PDF:

```{r setup, include=FALSE}
knitr::opts_chunk$set(dev = 'pdf')
```

然后,所有的图片和PDF文件都会很开心.

第二个问题是在out.width/out.height中混合了HTML单元和LaTeX单元.LaTeX和HTML是非常不同的技术.你不应该期望\maxwidth在HTML中工作,或者200px在LaTeX中工作.尤其是当你想将markdown 转换为latex 时,最好不要设置out.width/out.height(使用fig.width/fig.height,让latex 使用原始尺寸).

R相关问答推荐

仅返回R中所有其他列的列ID和年份缺失(NA)数据的列表

列出用m n个值替换来绘制n个数字的所有方法(i.o.w.:R中大小为n的集合的所有划分为m个不同子集)

如何使用`ggplot2::geom_segment()`或`ggspatial::geom_spatial_segment()`来处理不在格林威治中心的sf对象?

gt()从gt为相同内容的单元格 colored颜色 不同?

在不安装软件包的情况下测试更新

derrr summarise每个组返回多行?

手动打印线型gplot

在某些栏和某些条件下,替换dfs列表中的NA

在R中将特定列的值向右移动

如何在R中对深度嵌套的tibbles中的非空连续行求和?

为什么当用osmdata映射R时会得到相邻状态?

用关联字符串替换列名的元素

如何在R forestplot中为多条垂直线分配唯一的 colored颜色 ?

用R ggplot2求上、下三角形中两个变量的矩阵热图

R中有约束的优化问题:如何用复数和对数效益函数解决问题?

为什么在BASE R中绘制线条时会看到线上的点?

如何使这些react 表对象相互独立?

R代码,用于在线条图下显示观测表

使用列中的值来调用函数调用中应使用的其他列

计算Mean by分组和绑定到R中的数据集