r - ggplotly与geom_rect不显示geom_bar
问题描述
我有一个ggplot我想有一个灰色和白色的条纹背景。我已经使用 实现了这一点geom_rect
,如下所示:
ggplot(growth.mon, aes(x = Month, y = Rate)) +
geom_rect(ymin = 0.3, ymax = 0.4,
xmin = 0, xmax = 1000000, fill = '#fbfcfc') +
geom_rect(ymin = 0.2, ymax = 0.3,
xmin = 0, xmax = 1000000, fill = '#f5f6f9')+
geom_rect(ymin = 0.1, ymax = 0.2,
xmin = 0, xmax = 1000000, fill = '#fbfcfc')+
geom_rect(ymin = 0, ymax = 0.1,
xmin = 0, xmax = 1000000, fill = '#f5f6f9')+
geom_rect(ymin = -0.1, ymax = 0,
xmin = 0, xmax = 1000000, fill = '#fbfcfc')+
geom_rect(ymin = -0.2, ymax = -0.1,
xmin = 0, xmax = 1000000, fill = '#f5f6f9')+
geom_rect(ymin = -0.3, ymax = -0.2,
xmin = 0, xmax = 1000000, fill = '#fbfcfc')+
geom_bar(stat = "identity", aes(fill = as.factor(1)), show.legend = FALSE)+
geom_line(aes(y = rollMean, colour = "#7f5ba2"), size = 1.1, show.legend = FALSE)+
scale_fill_manual(values = c("#0095db"))+
scale_colour_manual(values = c("#7f5ba2"))+
scale_y_continuous(NULL, labels = percent_format())+
scale_x_date(date_breaks = "1 month", date_labels = "%b %Y")+
theme(axis.text.x=element_text(angle=60, hjust=1))+
theme(legend.position = "none")
这将创建:
现在我正在开发一个shiny应用程序,我希望这个图是交互式的而不是静态的,所以我像这样使用ggplotly:
ggplotly(gg_growth)
但是,图表最终会删除这样的条形:
有人可以告诉我出了什么问题以及如何解决这个问题吗?谢谢你。
数据:
dates <- seq(as.Date("2017-02-01"), length = 36, by = "1 month") - 1
sales_mon17 <- c(1503, 1563, 1434.5,1807, 1843.7, 1664, 1285, 1188, 1513, 1997,1718.2, 2191)
sales_mon18 <- c(1919, 1886, 1995, 1930, 1898, 2122, 1818, 1908, 1974, 2074, 1700, 2303)
sales_mon19 <- c(2319, 2424, 2353, 2474, 2500, 2538, 2444, 2219, 1908, 2404, 2288, 3079.7)
monthly_revenue <- data.frame(Month = dates, Revenue = c(sales_mon17, sales_mon18, sales_mon19))
growth.mon <- diff(monthly_revenue$Revenue) / lag(monthly_revenue$Revenue)[-1]
growth.mon <- data.frame(Month = monthly_revenue$Month[-1], Rate = growth.mon)
growth.mon$rollMean <- c(NA, NA, rollmean(growth.mon$Rate, 3))
解决方案
推荐阅读
- mysql - MySQL如何更新同一张表中的字段值?
- matlab - Matlab 只返回函数
- xml - 使用 xslt/ c# 比较两个 xml 文件
- android - anastr 问题 - 为什么 speedView 没有出现在工作室布局编辑器中?
- python - 在 Python 中更改多维列表中的重复值
- html - 如何删除 Chrome 扩展程序上的链接焦点轮廓?
- php - PDO 设置查询表变量
- php - 对预检请求的响应未通过访问控制检查:没有“访问控制允许来源”
- python - AttributeError:'str'对象没有属性'get',实际上是一个字典
- javascript - 防止页面在折叠的手风琴部分向上滚动。引导程序 4