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)
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With