获取 R Markdown 错误消息 - fortify(data, ...) 中的错误
错误消息:
fortify()
中出现错误: ! data
必须是数据框,或可通过 fortify()
强制转换的其他对象,而不是类 uneval 的 S3 对象。 您是否不小心将 aes()
传递给了 data
参数? 回溯:
- ggplot2::ggplot(aes(x = 因子(十年), y = 收入, 颜色 = 性别))
- ggplot2:::ggplot.default(...)
- ggplot2:::fortify.default(数据, ... ) 显示回溯 fortify(data, ...) 中的错误:
我的代码
``` {r pressure, message=FALSE, echo=FALSE}
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
load("file.RData")
filter(decade == 1980 | decade == 2010) +
ggplot(aes(x = factor(decade), y = income, colour = sex)) +
geom_boxplot() +
facet_grid(cols = vars(race)) +
scale_y_log10() +
ggtitle("Race and Gender Pay Gap - Visual 1") +
labs(y= "Annual Income", x = "Year") +
labs(colour = "Gender") +
theme_bw() +
scale_color_brewer(palette = "Set2")
这就是我的数据集的样子:
year sex age income degree race ID decade
<dbl> <chr> <dbl> <dbl> <chr> <chr> <dbl> <dbl>
1 1981 male 34 10000 yes white 1 1980
2 1981 male 32 9095 no black 2 1980
3 2009 male 64 45200 no black 3 2000
4 1999 male 50 25000 no white 4 1990
5 1990 male 26 24500 no white 5 1990
6 2011 male 39 46500 yes white 6 2010
7 2007 male 40 60000 no white 7 2000
8 1990 male 47 39200 no white 8 1990
9 1981 male 30 20500 no white 9 1980
10 2007 male 55 33000 no white 10 2000
任何帮助将不胜感激!谢谢:D
Error message:
Error in fortify()
:
! data
must be a data frame, or other object coercible by fortify()
, not an S3 object with class uneval.
Did you accidentally pass aes()
to the data
argument?
Backtrace:
- ggplot2::ggplot(aes(x = factor(decade), y = income, colour = sex))
- ggplot2:::ggplot.default(...)
- ggplot2:::fortify.default(data, ...)
Show Traceback
Error in fortify(data, ...) :
My code
``` {r pressure, message=FALSE, echo=FALSE}
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
load("file.RData")
filter(decade == 1980 | decade == 2010) +
ggplot(aes(x = factor(decade), y = income, colour = sex)) +
geom_boxplot() +
facet_grid(cols = vars(race)) +
scale_y_log10() +
ggtitle("Race and Gender Pay Gap - Visual 1") +
labs(y= "Annual Income", x = "Year") +
labs(colour = "Gender") +
theme_bw() +
scale_color_brewer(palette = "Set2")
This is what my data set looks like:
year sex age income degree race ID decade
<dbl> <chr> <dbl> <dbl> <chr> <chr> <dbl> <dbl>
1 1981 male 34 10000 yes white 1 1980
2 1981 male 32 9095 no black 2 1980
3 2009 male 64 45200 no black 3 2000
4 1999 male 50 25000 no white 4 1990
5 1990 male 26 24500 no white 5 1990
6 2011 male 39 46500 yes white 6 2010
7 2007 male 40 60000 no white 7 2000
8 1990 male 47 39200 no white 8 1990
9 1981 male 30 20500 no white 9 1980
10 2007 male 55 33000 no white 10 2000
Any help would be super appreciated!! Thanks :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码运行,可能需要添加
示例代码:
基于您的评论的解决方案:
情节:
示例数据:
Your code runs, probably need to add
Sample code:
Solution-based on your comment:
Plot:
Sample data: