Skip to content

Posting scatter points over grouped bars #5480

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

Closed
TonyBonen opened this issue Feb 8, 2021 · 1 comment
Closed

Posting scatter points over grouped bars #5480

TonyBonen opened this issue Feb 8, 2021 · 1 comment

Comments

@TonyBonen
Copy link

I want to have a plot with scatter points overtop of bars. The problem is that the locations (on the x axis in my case) of the bars cannot be passed to the scatter points - they always sit directly above the x-axis values rather than being spread out across the bars within a grouped category.

Its the same issue as being asked here: https://stackoverflow.com/questions/54591377/overlay-a-grouped-bar-chart-with-scatter-in-plotly

I'm working in R plotly but seems this problem appears also in the Python implementation. This example should produce the error:

example <- data.frame(country = rep(c("Canada", "France", "UK"), 2),
                    sex =  rep(c('men', 'women'), 3),
                    value1 = 1:6 + 7,
                    value2 = rep(14:12, 2))

 plot_ly(example) %>% 
       add_trace(type = 'bar',
           x = ~sex, 
           color=  ~country, 
            y=  ~value1)   %>%

    add_trace(type = 'scatter', mode="markers",
            x = ~sex, 
            marker = list(size = 8, color = "#000000"),
             y=  ~value2)  

The result is something like the screen shot below where in the 2 groups (men and women) the 3 scatter points are lined up in the middle of the group. The desired behaviour is to have those points appear above their respective colour/country groups.

image

@alexcjohnson
Copy link
Collaborator

Duplicate of #4913 - I'll copy your comment over there because of the nice example & picture.

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