我正在构建一个ggplot包装函数,用于多个绘图。现在我得到这个错误,我不明白。
这是我的职责:
library(tidyverse)
plot_hist_trend <- function(df, title, subtitle = "", x_axis, y_axis, point_color) {
df %>%
ggplot(aes(x_axis, y_axis)) +
geom_smooth(color = "black") +
geom_point(color = point_color) +
theme(legend.position = "right") +
labs(title = title,
subtitle = subtitle,
x = "",
y = "",
caption = "Data: NOAA")
}
这是我的数据帧的一个子集。
df <- structure(list(year = c(2018L, 2017L, 2016L, 2015L, 2014L), n = c(52L,
53L, 47L, 47L, 55L)), .Names = c("year", "n"), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame"))
…但是当我绘制ggplot2对象时,我遇到了这个
1d atomic vector or list
plot_hist_trend(df, title = "Title",
x_axis = year, y_axis = n,
point_color = "#D0021B")
提前通知Tnx!