阴影区域未显示在阴影对象中

时间:2017-09-04 13:37:02

标签: r plotly

我已经构建了一个带阴影区域的ggplot2对象。不幸的是,当将ggplotly应用于ggplot2对象时,我无法让这些阴影区域显示出来。

$( event.target ).window.location.href='http://www.google.com';

ggplot2对象(带阴影区域)位于

之下

Plot with shaded areas

1 个答案:

答案 0 :(得分:2)

您可以通过geom_bar将阴影区域绘制成阴谋。正如上面评论中提到的那样,情节确实支持这一点。

# define theX as middle point between theXmin & theXmax
dataFrameForShadedAreas$theX = rowMeans(dataFrameForShadedAreas[,1:2])

ggplotObj <- ggplot(data = theDataFrame, aes(x = game, y = score, color = season)) +
  geom_line() +
  geom_bar(data = dataFrameForShadedAreas, inherit.aes = FALSE,
           aes(x = theX, y = 100), # y should be set to some height beyond the chart's range; y = Inf doesn't work
           stat = "identity", position = "stack", width = 0.1,
           fill = "turquoise3", alpha = 0.2) +
  coord_cartesian(ylim = c(1, 4)) # set limit for y-axis range here

plotly chart