plotly / plotly/plotly.R

ggplotly date shows wrong when use geom_bar(stat='count')

Open
#1,124 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug ggplotly
Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

I find a problem that, when I use geom_bar(stat='count') to draw a plot and convert to plotly, when pointing to, the label shows date an integer, but when I aggregate the data first and use geom_bar(stat='identity'), the label shows date in proper format. The issue happened after I update to MRO 3.4.1, and try to solve the problem that ggplotly makes graph empty when x axis is date. I update both ggplot2 and plotly to github version that empty problem is gone, but new problem comes.

By the way. Is there a method that control the date format in the label?

devtools::install_github("hadley/ggplot2")
devtools::install_github("ropensci/plotly") 
library(ggplot2) 
library(plotly) 

df2 = data.frame(time = c('2017-01-01 06:00:23', '2017-01-01 10:00:23', 
                          '2017-01-01 18:00:23', '2017-01-01 24:00:23', 
                          '2017-01-02 06:00:23', '2017-01-02 10:00:23', 
                          '2017-01-02 18:00:23', '2017-01-03 24:00:23'), 
                 y = c(1:8)) 

df2.p = ggplot(df2 %>% mutate(date_id = as.Date(time)), aes(x = date_id, y = ..count..)) + 
  geom_bar(stat = 'count') 

ggplotly(df2.p) 

df3 = df2 %>% mutate(date_id = as.Date(time)) %>% 
  group_by(date_id) %>% summarise(
    count = n() 
  ) 
df3.p = ggplot(df3, aes(x = date_id, y = count)) + 
  geom_bar(stat = 'identity') 
ggplotly(df3.p) 
plotly_date_issue plotly

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible R examples in the issue and compare the ggplotly output for geom_bar(stat='count') with the stat='identity' version. Investigate how the date_id aesthetic is represented in each conversion; done means count-based bars display properly formatted date labels, with any date-format behavior clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.