Qia*_*eng 5 r ggplot2 plotly ggplotly
我正在尝试使用 ggplotly 和 facet_wrap 创建条形图。但是,第二个和第三个子图的 x 轴看起来很奇怪。下面是我的代码:
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)
Run Code Online (Sandbox Code Playgroud)
正如我发现的,这个问题与使用无关,scales="free_x"但在使用面板 > 1 中仅存在一个类别的离散轴时更常见(请参阅我的问题#1720和#1577)。
我查看了这个问题,并通过 PR #1788提出了解决此问题的解决方案,该 PR #1788 于 2020 年 6 月 18 日合并。
通过devtools::install_github("ropensci/plotly")您的示例安装最新的开发版本的plotly后,现在应该正确呈现,如下所示: