我想用图表中的分组数据创建黄土图。它无法正常工作,因为它只生成一行。这似乎是一个错误。
df <- data.frame(
id = rep(1:1000, 3),
value = c(rnorm(1000,mean = 2),
rnorm(1000,mean = 4),
rnorm(1000,mean = 6)),
var = rep(LETTERS[1:3], each = 1000))
# ggplot2 - it works as it should be
ggplot(df, aes(id, value, color = var)) +
geom_smooth(method = "loess")
# plotly - it doesn't work properly
df %>%
plot_ly(x = ~id) %>%
add_markers( y = ~value, color = ~var) %>%
add_lines(y = ~fitted(loess(value ~ id)), color = ~var)