首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ggplot错误-“无法将类‘c(”ScaleContinuousPosition“,"ScaleContinuous","Scale","ggproto",’)强制转换为data.frame”

ggplot错误-“无法将类‘c(”ScaleContinuousPosition“,"ScaleContinuous","Scale","ggproto",’)强制转换为data.frame”
EN

Stack Overflow用户
提问于 2019-12-07 01:24:21
回答 1查看 63关注 0票数 0

假设我在iris数据上尝试一个非常简单的ggplot图,它看起来像这样:

代码语言:javascript
复制
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_line() +
  theme_minimal() +
  scale_x_continuous(limits = c(5, 8)) %>%
  annotate(geom = "text", x = 6, y = 5, label = "We Love Flowers!", color = "#619CFF", size = 8)

出于某种原因,它会抛出这个错误:

代码语言:javascript
复制
Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class ‘c("ScaleContinuousPosition", "ScaleContinuous", "Scale", "ggproto", ’ to a data.frame

怎么回事?到底怎么回事?

EN

回答 1

Stack Overflow用户

发布于 2019-12-07 01:24:21

听着,我们都经历过。在dplyrggplot之间切换,忘记在%>%管道和+操作符之间切换。发生在我们最好的人身上!

修正后的代码如下:

代码语言:javascript
复制
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_line() +
  theme_minimal() +
  scale_x_continuous(limits = c(5, 8)) +
  annotate(geom = "text", x = 6, y = 5, label = "We Love Flowers!", color = "#619CFF", size = 8)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59217714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档