【问题标题】:Error while knitting rmd file with ggplot使用 ggplot 编织 rmd 文件时出错
【发布时间】:2018-02-13 06:32:18
【问题描述】:
library(ggplot2) #done this multiple times, and rmd works fine!
RIStopData<-read.csv("RIStopData.csv", sep=",")
p1 = ggplot(RIStopData, aes(x=driver_gender , y=as.numeric(stop_time)))
p1 + geom_boxplot()

当我在 R markdown 中运行该块时,这给出了一个很好的箱线图。但是当我尝试使用knit 功能将其导出到 html 时,R 在第二行本身给出以下错误:

Error in ggplot(RIStopData, aes(x=driver_gender , y=as.numeric(stop_time))) : could
not find function "ggplot" Calls: <Anonymous> ... handle-> withCallingHandlers ->
withVisible -> eval -> eval Execution halted

这是我运行代码块后在markdown中得到的箱线图。

【问题讨论】:

  • 安装后请加载库,即library(ggplot2)(如果未安装)
  • 多次这样做只是为了确定。但不要认为这是问题,因为代码块运行并绘制箱线图就好了。
  • 您的错误状态为could not find function "ggplot"
  • 是的,但这就是我检查库是否已加载的原因。无论如何再次加载它,但我仍然得到同样的错误。 rmd 文件使用ggplot 运行,因此库被加载。
  • islibrary(ggplot2) 在你 rmd 上的 r 块中?

标签: r function ggplot2 r-markdown knitr


【解决方案1】:

我们尝试使用内置数据集 mtcars 运行降价。 .rmd 文件如下所示

---
title: "ggplot"
author: "akrun"
date: "February 13, 2018"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown


```{r ggplot}
library(ggplot2)
data(mtcars)
p1 = ggplot(mtcars, aes(x=factor(gear) , y=mpg))
p1 + geom_boxplot()


```

-输出

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    相关资源
    最近更新 更多