我想简单地在Quarto中想象一个情节,但不断收到一个错误,我不明白.当我运行我的qmd
文件时,我在这个块中得到一个错误:
ggplot(df, aes(x = X, y = Y)) +
geom_bin2d(binwidth = c(5, 5)) +
stat_bin2d(geom = "text", aes(label = ..count..), size = 2, binwidth = c(5, 5)) +
scale_fill_gradient("Aantal schoten", low = "yellow", high = "red") +
annotate_pitch(alpha = 0) +
direction_label(x_label = 50) +
theme_pitch() +
theme(legend.key=element_blank())
错误:
Error in `ggplot()`:
! `data` cannot be a function.
ℹ Have you misspelled the `data` argument in `ggplot()`
Backtrace:
1. ggplot2::ggplot(df, aes(x = X, y = Y))
2. ggplot2:::ggplot.function(df, aes(x = X, y = Y))
Execution halted
我判断了我的全局环境,没有名为data
的变量,这可能是问题所在.当我运行一个简单的类似文件时,不会出现这样的错误:
---
title: "test"
---
```{r}
library(ggplot2)
library(dplyr)
iris %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point()
```
所以我不明白为什么这个错误总是发生.我也try 在ggplot
函数中使用data = df
,但这不起作用.此外,在逐个块运行代码块时,代码块也可以工作.该错误仅在渲染文件时发生.那么,有人知道为什么会发生这个错误吗?