假设我在iris数据上尝试一个非常简单的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)出于某种原因,它会抛出这个错误:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ‘c("ScaleContinuousPosition", "ScaleContinuous", "Scale", "ggproto", ’ to a data.frame怎么回事?到底怎么回事?
发布于 2019-12-07 01:24:21
听着,我们都经历过。在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)https://stackoverflow.com/questions/59217714
复制相似问题