Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hover not working for barplot with two levels #868

Closed
romunov opened this issue Feb 2, 2017 · 1 comment
Closed

hover not working for barplot with two levels #868

romunov opened this issue Feb 2, 2017 · 1 comment

Comments

@romunov
Copy link

romunov commented Feb 2, 2017

User Marta posted a question on StackOverflow and it would appear this is a bug. Hover doesn't appear to be working for barplots with two levels.

xylong <- structure(list(rok = c(2016, 2016, 2016, 2016, 2016, 2016, 2016, 
                       2016, 2016, 2017, 2017), miesiac = c(4, 5, 6, 7, 8, 9, 10, 11, 
                                                            12, 1, 2), ile = c(80.1, 87.5, 159, 104, 125.3, 74.2, 84.9, 74.4, 
                                                                               75.3, 81.8, 2.4), kwartal = c(2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1
                                                                               ), miesiac2 = c("1", "2", "3", "1", "2", "3", "1", "2", "3", 
                                                                                               "1", "2"), kwartal2 = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 
                                                                                                                                 3L, 3L, 4L, 4L), .Label = c("Q2 2016", "Q3 2016", "Q4 2016", 
                                                                                                                                                             "Q1 2017"), class = "factor"), miesiac3 = c("Kwiecień", "Maj", 
                                                                                                                                                                                                         "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", 
                                                                                                                                                                                                         "Listopad", "Grudzień", "Styczeń", "Luty"), limit = c(308, 308, 
                                                                                                                                                                                                                                                               308, 300, 300, 300, 245, 245, 245, 244, 244), serwis = c("Sport", 
                                                                                                                                                                                                                                                                                                                        "Sport", "Sport", "Sport", "Sport", "Sport", "Sport", "Sport", 
                                                                                                                                                                                                                                                                                                                        "Sport", "Sport", "Sport"), typ = c("odslony", "odslony", "odslony", 
                                                                                                                                                                                                                                                                                                                                                            "odslony", "odslony", "odslony", "odslony", "odslony", "odslony", 
                                                                                                                                                                                                                                                                                                                                                            "odslony", "odslony"), ile2 = c(326.6, 326.6, 326.6, 303.5, 303.5, 
                                                                                                                                                                                                                                                                                                                                                                                            303.5, 234.6, 234.6, 234.6, 84.2, 84.2), ile_proc = c(25, 27, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                  49, 34, 41, 24, 36, 32, 32, 97, 3), lp = c(1, 1, 1, 2, 2, 2, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             3, 3, 3, 4, 4)), class = "data.frame", .Names = c("rok", "miesiac", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               "ile", "kwartal", "miesiac2", "kwartal2", "miesiac3", "limit", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               "serwis", "typ", "ile2", "ile_proc", "lp"), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         -11L))

xyshort <- structure(list(rok = c(2017, 2017), miesiac = c(1, 2), ile = c(31.5, 
                                                                          1), kwartal = c(1, 1), miesiac2 = c("1", "2"), kwartal2 = structure(c(1L, 
                                                                                                                                                1L), .Label = "Q1 2017", class = "factor"), miesiac3 = c("Styczeń", 
                                                                                                                                                                                                         "Luty"), limit = c(97, 97), serwis = c("Sport", "Sport"), typ = c("wizyty", 
                                                                                                                                                                                                                                                                           "wizyty"), ile2 = c(32.5, 32.5), ile_proc = c(97, 3), lp = c(1, 
                                                                                                                                                                                                                                                                                                                                        1)), class = "data.frame", .Names = c("rok", "miesiac", "ile", 
                                                                                                                                                                                                                                                                                                                                                                              "kwartal", "miesiac2", "kwartal2", "miesiac3", "limit", "serwis", 
                                                                                                                                                                                                                                                                                                                                                                              "typ", "ile2", "ile_proc", "lp"), row.names = c(NA, -2L))   

library(plotly)

# hover doesn't work for two levels
plot_ly(xyshort, 
        x = ~lp, 
        y = ~ile, 
        color = ~miesiac2,
        colors = cols, # explicitly name colors
        type = "bar", 
        text = ~miesiac3,
        hoverinfo = "text")

# hover works for more levels
plot_ly(xylong, 
        x = ~lp, 
        y = ~ile, 
        color = ~miesiac2,
        type = "bar", 
        text = ~miesiac3,
        hoverinfo = "text")

# also doesn't work if coercing a ggplot() object using ggplotly()
ggplotly(ggplot(xyshort, aes(x = lp, y = ile, fill = miesiac2)) +
  theme_bw() +
  geom_bar(stat = "identity", position = "dodge")
)
@cpsievert
Copy link
Collaborator

The first two examples now work (I think because of a bugfix in plotly.js). Not sure what's going on with the last example, but I think it may be because the bars are so close to the margins, plotly.js decides not to draw them...

Closing since I don't think this is a problem I can fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants