rmarkdown和Morris图表到HTML

时间:2015-04-08 15:05:23

标签: r knitr r-markdown rcharts morris.js

尝试使用rMarkdown创建Morris图表并将其发送到rPubs。但是,我无法让图表呈现:

```{r, results='asis', echo=FALSE, comment=NA}
library(rCharts)
library(ggplot2)
library(reshape2)
library(knitr)

summary(cars)

data=read.csv("prop by race.csv")


data$Poll=format(as.Date(data$Poll, "%m/%d/%Y"))


data=transform(data,White=White*100, Black=Black*100, Hispanic=Hispanic*100)


m1<-mPlot(x="Poll", postUnits="%",  smooth="false", y=c("White","Black","Hispanic"), type="Line", data=data, lineColors=c("darkblue","red","orange"))


m1$print('chart2',include_assets=TRUE, cdn=TRUE)

```

我收到以下错误:

pandoc.exe: Could not find data file //cdn.oesmith.co.uk/morris-0.4.2.min.css
Error: pandoc document conversion failed with error 97
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" test_markdown.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output test_markdown.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\rcarvalho\Documents\R\win-library\3.1\rmarkdown\rmd\h\default.html" --variable "theme:bootstrap" --include-in-header "C:\Users\RCARVA~1\AppData\Local\Temp\Rtmp6rAH4a\rmarkdown-str2238e3c164f.html" --mathjax --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --no-highlight --variable "highlightjs=C:\Users\rcarvalho\Documents\R\win-library\3.1\rmarkdown\rmd\h\highlight"' had status 97 
Execution halted

1 个答案:

答案 0 :(得分:0)

您可以使用此处说明的方法正确呈现图表:

2 Knitr/R Markdown/Rstudio issues: Highcharts and Morris.js

您的代码块如下所示:使用morris.js示例:

http://timelyportfolio.github.io/rCharts_morris_gettingstarted/

```{r results = 'asis', comment = NA}
require(rCharts)
#specify the data
data = data.frame(
  c('2008', '2009', '2010', '2011', '2012'),
  c(20,10,5,5,20),
  stringsAsFactors = FALSE)

colnames(data) <- c("year","value")
#build the plot
m1 <- mPlot(
  x = "year",
  y = "value",
  data = data,
  type = "Line")
m1$set( labels = "value" ) 
m1$print('chart2', include_assets = TRUE)
```

对于将来的问题,请尝试包含可重现的数据示例(data=read.csv("prop by race.csv")不可重现)。