Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X axis error with ggplotly and facet_wrap

I am trying to create a bar plots with ggplotly and facet_wrap. However, the x-axis looks weird for the second and third subplots. below is my code:

library(plotly)
library(ggplot2)
library(dplyr)

setInfo<- data.frame(sampleNumber=rep(c("A","B","C"),4),
                     Category=rep(c("Class 1", "Class 2","Class 3"),4),
                     Value=rep(1,12))

setInfo %>% 
  ggplot(aes(sampleNumber,fill = sampleNumber))+
  geom_bar()+
  facet_wrap(~Category,nrow = 1,scales = "free_x")->plot_this

ggplotly(plot_this)
like image 261
Qianshun Cheng Avatar asked Nov 06 '22 09:11

Qianshun Cheng


1 Answers

This issue is fixed via PR #1788.

As I figured out this issue was not related to the use of scales="free_x" but happened more generally when using a discrete axis with only one category present in panels > 1 (see my issue #1720 and also #1577).

I have had a look on the issue and was able to come up with a solution to fix this via PR #1788 which was merged on 2020-06-18.

After installing the latest devel version of plotly via devtools::install_github("ropensci/plotly") your example should now be rendered correctly like so:

enter image description here

like image 58
stefan Avatar answered Nov 12 '22 20:11

stefan