ggplotly堆积面积图没有cumsum标签

ggplotly stacked area plot without cumsum labels

问题来了。使用此代码:

library(ggplot2)
library(plotly)

Values1 <- rep(10, 10)
Values2 <- rep(20, 10)
X <- rep(seq(1, 10),2)
df <- data.frame(Values1=Values1, Values2=Values2)
df <- melt(df)
df2 <- data.frame(X=X, Label=df$variable, Value=df$value)

Plot <- ggplot(data=df2, aes(x=X, y=Value)) + 
  geom_area(data=df2, aes(fill=Label), position='stack')
ggplotly(Plot)

我在堆叠区域上的标签显示 Values1+Values2 而不是 Values1 的值。

我该如何解决这个问题?

添加 texttooltip 会给你想要的东西:

Plot <- ggplot(data=df2, aes(x=X, y=Value, fill=Label, text = paste("Value:", Value))) + 
geom_area(position='stack')
ggplotly(Plot) 
ggplotly(tooltip = c("text", "x", "fill"))