我正在使用 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")
```
这在每个先例代码块和文档中都以相同的方式工作,但是现在当我编织文档时它会引发此错误:
我已经尝试了任何我知道的方法,它会在调用
curve(pleft50,...
后立即引发它。谢谢你的回答,对不起我的英语!
最佳答案
它不喜欢第一行中的 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")
```
你得到这个:
关于r - 绘制编织错误 : "unable to start png() device",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49832109/