我正在使用Rmarkdown制作漂亮的文档(比如LaTex),但是有一个问题我无法解决。
我按以下方式打印图表:
```{r p(s|r)}
pleft=function(x, p=0.5){dnorm(x, mean=35, sd = 10)*p/(dnorm(x, mean=35, sd
= 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pright=function(x, p=0.5){dnorm(x, mean=65, sd = 10)*(1-p)/(dnorm(x,
mean=35, sd = 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pleft50= function(x){pleft(x, 0.5)}
pright50=function(x){pright(x, 0.5)}
curve(pleft50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="red", lwd=2)
curve(pright50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="blue", lwd=2, add=TRUE)
legend("right", legend = c("p(Left|r)","p(Right|r)"), col=c('red', 'blue'),
lwd = 2)
title("Posteriors")
```
这在每个先前的代码块和文档中都以相同的方式工作,但是现在当我编写文档时它会引发这个错误:
png错误(...,res = dpi,units =“in”):无法启动png()设备调用:... in_dir - > plot2dev - > do.call - > - > png另外:警告信息:1:在png(...,res = dpi,units =“in”)中:无法打开文件'ExSheet4_files / figure-html / my chunk-1.png的名字'用于写2 :在png(...,res = dpi,units =“in”)中:打开设备失败
我已经尝试过任何我知道的东西,只要调用curve(pleft50,...
就会提高它。
感谢您的回答,对不起我的英语!
答案 0 :(得分:2)
它不喜欢第一行中的p(s|r)
- 它正在尝试创建一个用于写入的文件,并且它在那里失败了。如果你删除它,例如:
---
title: "Untitled"
date: "April 14, 2018"
output:
html_document: default
word_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
pleft=function(x, p=0.5){dnorm(x, mean=35, sd = 10)*p/(dnorm(x, mean=35, sd
= 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pright=function(x, p=0.5){dnorm(x, mean=65, sd = 10)*(1-p)/(dnorm(x,
mean=35, sd = 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pleft50= function(x){pleft(x, 0.5)}
pright50=function(x){pright(x, 0.5)}
curve(pleft50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="red", lwd=2)
curve(pright50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="blue", lwd=2, add=TRUE)
legend("right", legend = c("p(Left|r)","p(Right|r)"), col=c('red', 'blue'),
lwd = 2)
title("Posteriors")
```
你明白了:
答案 1 :(得分:0)
当您在已命名的代码块中编织图时,发生了所描述的错误,并且在编织过程中,块的名称未导致有效的路径名。
也就是说,在编织过程中,将图形写入包含代码块名称的临时路径中,因此,此名称应仅包含对路径名称有效的字符,而对于所用字符{ {1}}。一个人也应该避免对|
使用白色字符。