使用ggplot编织rmd文件时出错

时间:2018-02-13 06:32:19

标签: r function ggplot2 r-markdown knitr

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中得到的箱线图。

enter image description here

1 个答案:

答案 0 :(得分:0)

我们尝试使用内置数据集mtcars运行markdown。 .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()


```

-output

enter image description here