R Markdown:剧情腐败

时间:2018-03-27 00:47:39

标签: r rstudio r-markdown knitr

下面的代码可以很好地作为一个块,编织得很好,并且html在RStudio查看器中看起来很好。但是,当我在浏览器(Chrome版本65.0.3325.181或Safari)中打开html时,每个直方图都有重叠的条形图,并且在points()调用中调整lwd没有帮助。我正在运行OSX 10.9.5,R 3.3.3和RStudio 1.1.383。我知道有更简单的方法可以将两个直方图放在同一个图上,但我想了解这里发生的事情; RStudio / RMarkdown对我来说一直都很完美。谢谢。 -n

How it looks in a browser

道歉。这是整个Rmd。 (YAML标题在这里,但它们拒绝出现,即使是一个块引用。请原谅我的无知。)

标题:“奇怪的情节行为”   作者:“尼尔弗雷泽”   日期:“2018年3月24日”   输出:   html_document   fig_caption:是的

<style type="text/css">
h1.title{/* Normal */ font-size:20px}
body{ /* Normal  */ font-size: 14px}
td {  /* Table   */ font-size: 12px}
h1 { /* Header 1 */ font-size: 16px}
h2 { /* Header 2 */ font-size: 14px}
h3 { /* Header 3 */ font-size: 14px}
h4 { /* Header 4 */ font-size: 13px}
code.r{ /* Code block */ font-size: 14px}
pre { /* Code block */ font-size: 14px}
p.caption {font-size: 14px}
</style>

```{r setup, echo=FALSE}
rm(list=ls()) # clean up
library(knitr)
#library(coda)
gr <- (1+sqrt(5))/2 # golden ratio, for figures
opts_chunk$set(comment="  ",
               collapse=TRUE, 
               echo=FALSE,
               fig.asp=1/gr,
               fig.height=5,
               dev="svg",
               warning=TRUE
               )
opts_knit$set(eval.after = "fig.cap") 
```  

```{r histograms, out.width=800, out.height=400}
# synthetic data for test
daysAdlib <- abs( rnorm(200,mean=300,sd=100) )
daysRestr <- abs( rnorm(200,mean=500,sd=100) )
unit      <- 50L
break1 <- unit*floor(min(daysAdlib,daysRestr)/unit)
break2 <- unit*ceiling(max(daysAdlib,daysRestr)/unit)
breaks <- seq(from=break1,to=break2, by=unit)
histRestr <- hist(daysRestr, plot=FALSE, breaks=breaks)
histAdlib <- hist(daysAdlib, plot=FALSE, breaks=breaks)
xlim <- range(breaks)
ylim <- range(0, 1.05*max(histAdlib$density,histRestr$density) )
myred  <- rgb(255,0,0,max=255,alpha=120,names="blue50")
myblue <- rgb(0,0,255,max=255,alpha=120,names="red50" )
plot(0,0, xlim=xlim, ylim=ylim, type="n",
     xlab="Days lived", ylab="density") 
lwd <- unit/2 
points(histAdlib$mids, histAdlib$density, type="h",
      col=myblue, lwd=lwd, lend="butt")
points(histRestr$mids, histRestr$density, type="h",
      col=myred, lwd=lwd, lend="butt")
legend("topright", inset=0.05,
       col=c(myblue,myred), 
       pch=c(15,15),
       pt.cex=c(1.5,1.5),
       legend=c("Ad lib","Restricted")
       )
``` 

0 个答案:

没有答案
相关问题