假设我正在对ggplot
数据进行超简单的iris
绘制,它看起来像这样:
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)
由于某种原因,它会引发此错误:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ‘c("ScaleContinuousPosition", "ScaleContinuous", "Scale", "ggproto", ’ to a data.frame
有什么作用?发生了什么事?
答案 0 :(得分:1)
听,我们都去过那里。在dplyr
和ggplot
之间切换,而忘记在%>%
管道和+
运算符之间切换。发生在我们当中最好的!
更正后的代码如下:
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)