【问题标题】:rmarkdown and Morris chart to HTMLrmarkdown 和 Morris 图表转 HTML
【发布时间】:2015-04-08 15:05:23
【问题描述】:

尝试使用 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

【问题讨论】:

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


    【解决方案1】:

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

    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") 不可重现)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 2014-06-09
      • 2019-11-20
      • 1970-01-01
      • 2020-04-26
      相关资源
      最近更新 更多