Skip to content

geom_bar() + coord_flip() doesn't work #390

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
jseppanen opened this issue Jan 13, 2016 · 2 comments
Closed

geom_bar() + coord_flip() doesn't work #390

jseppanen opened this issue Jan 13, 2016 · 2 comments
Labels

Comments

@jseppanen
Copy link

When plotting a bar chart with ggplot2 and plotly, the plot is empty on our enterprise plotly server.

This is the expected result:
empty_plot_ggplot

This is what I get with plotly:
empty_plot_plotly

Code:

library(ggplot2)
library(scales)
library(plotly)

d <- read.csv('empty_plot_data.csv.txt')

png('empty_plot_ggplot.png', w=500, h=300, res=96)
p <- ggplot(d, aes(purchase, revenue, fill=currency)) +
    geom_bar(stat='identity') +
    scale_y_continuous(label=dollar) +
    scale_fill_manual(values=c('limegreen', 'orange')) +
    labs(x=NULL, y='Revenue (USD)', title='Stuff bought') +
    coord_flip() +
    theme_bw()
print(p)
dev.off()

t <- plotly_POST(p, filename='empty_plot',
                 fileopt='overwrite', world_readable=TRUE)

csv file:
empty_plot_data.csv.txt

@cpsievert
Copy link
Collaborator

There are a couple problems here. The biggest of which is that coord_flip() doesn't currently work with geom_bar():

d <- read.csv("https://github.com/ropensci/plotly/files/89254/empty_plot_data.csv.txt")
p <- ggplot(d, aes(purchase, revenue, fill = currency)) +
  geom_bar(stat = 'identity') + 
  coord_flip()
ggplotly(p)

We'll provide a fix for this eventually, but for the time being, you could build the plot and change the orientation of the bars

l <- plotly_build(p)
l$data[[1]]$orientation <- "h"
l$data[[2]]$orientation <- "h"
l

PS. It's a known issue that we don't yet convert some tick label formats such as scale_y_continuous(label=dollar), so I'll be ignoring that in this issue.

@cpsievert cpsievert changed the title Bar chart is empty geom_bar() + coord_flip() doesn't work Jan 13, 2016
@cpsievert cpsievert added the bug label Jan 14, 2016
@raghavkgarg
Copy link

How Does reorder (or sort) works in plotly , like in above example lowest value(some stuff row) at lowest place and highest value at top(plain stuff row).

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

No branches or pull requests

3 participants