r - Plotly GGplot - 情节响应
问题描述
代码输出是一个我希望它响应的图,以根据窗口尺寸进行调整。使用只是ggplot
给了我想要的结果,但我想使用交互式工具提示plotly
,但是当我这样做时,该图没有响应。
有什么可以解决的吗?代码如下。我真的很感激任何帮助!
library(dplyr)
library(ggplot2)
library(lubridate)
library(plotly)
df <- data.frame(matrix(c("2017-09-04","2017-09-05","2017-09-06","2017-09-07","2017-09-08",103,104,105,106,107,17356,18022,17000,20100,15230),ncol = 3, nrow = 5))
colnames(df) <- c("DATE","ORDER_ID","SALES")
df$DATE <- as.Date(df$DATE, format = "%Y-%m-%d")
df$SALES <- as.numeric(as.character(df$SALES))
df$ORDER_ID <- as.numeric(as.character(df$ORDER_ID))
TOTALSALES <- df %>% select(ORDER_ID,DATE,SALES) %>% mutate(weekday = wday(DATE, label=TRUE)) %>% mutate(DATE=as.Date(DATE)) %>% filter(!wday(DATE) %in% c(1, 7) & !(DATE %in% as.Date(c('2017-01-02','2017-02-27','2017-02-28','2017-04-14'))) ) %>% group_by(day=floor_date(DATE,"day")) %>% summarise(sales=sum(SALES)) %>% data.frame()
TOTALSALES <- ggplot(TOTALSALES ,aes(x=day,y=sales,text=paste('Vendas (R$):', format(sales,digits=9, decimal.mark=",",nsmall=2,big.mark = "."),'<br>Data: ',format(day,"%d/%m/%Y"))))+ geom_point(colour = "black", size = 1)+stat_smooth() +labs(title='TOTAL SALES',x='dias',y='valor')+ scale_x_date(date_minor_breaks = "1 week")
m <- list(
l = 120,
r = 2,
b = 2,
t = 50,
pad = 4
)
TOTALSALES <- ggplotly(TOTALSALES,tooltip = c("text")) %>% config(displayModeBar = F) %>% layout(autosize = F, width = 1000, height = 500, margin = m,xaxis = list(
zeroline = F
),
yaxis = list(
hoverformat = '.2f'
))
TOTALSALES
解决方案
推荐阅读
- ruby-on-rails - 使用 SimpleForm simple_fields_for 创建一个新对象而不是更新当前对象
- php - Podio 不解析通过 API 发送的位置
- typo3 - TYPO3 tx_news 存档列表
- algorithm - Union Find Disjoint Set 的朴素功能实现性能不佳
- ios - 约束视图中的按钮,使它们都均匀分布
- bayesian - 使用 pymc3 拟合 lomax 模型
- reactjs - Google-OAuth REST Api 做出反应
- python - python glob.glob() regex multi files in different dir
- vba - 如果存在则覆盖工作表
- jquery - 表单提交后无法让锚标签在jquery mobile中工作