当我在ggplotly()中为具有大量构面组的闪亮应用程序执行facet_grid时,情节会混乱。但它在Shiny之外正常工作。R:facet_wrap无法正确显示ggplotly中的闪亮应用程序
我该如何解决这个问题?
我怀疑它是连接到Y规模,但我找不到解决方案。
下面是基于diamonds example from plotly的可重复的示例。闪亮的
比较与非闪亮输出:Comparison of facet_grid outside and within Shiny
代码
外闪亮:
library(ggplot2)
data(diamonds, package = "ggplot2")
# new faceting group
diamonds$rdmGroup <- as.factor(sample(LETTERS, dim(diamonds)[1], replace=TRUE))
# subset of diamonds
diamonds <- diamonds[sample(nrow(diamonds), 1000),]
ggplot(diamonds , aes_string(x = diamonds$x, y = diamonds$y, color = diamonds$x)) +
geom_point() + facet_grid(rdmGroup~.) +
guides(color=FALSE) +
labs(x = "X", y="Y")
相同的代码在一个闪亮的应用程序:
library(shiny)
library(plotly)
library(ggplot2)
data(diamonds, package = "ggplot2")
# new faceting group
diamonds$rdmGroup <- as.factor(sample(LETTERS, dim(diamonds)[1], replace=TRUE))
# subset of diamonds
diamonds <- diamonds[sample(nrow(diamonds), 1000),]
ui <- fluidPage(
headerPanel("Diamonds Explorer"),
sidebarPanel(
sliderInput('plotHeight', 'Height of plot (in pixels)',
min = 100, max = 2000, value = 1000)
),
mainPanel(
plotlyOutput('trendPlot')
)
)
server <- function(input, output) {
output$trendPlot <- renderPlotly({
p <- ggplot(diamonds, aes_string(x = diamonds$x, y =diamonds$y, color = diamonds$x)) +
geom_point()+ facet_grid(rdmGroup~., scales = "free_y") +
labs(x = "X", y="Y")
ggplotly(p) %>%
layout(height = input$plotHeight, autosize=TRUE)
})
}
shinyApp(ui, server)
PS:)我用aes_string(而不是AES()故意,因为我需要它在我真正的应用程序。
我运行你的例子,当获得大量的警告。您是否尝试安装ggplot2的最新github版本? “我们建议您使用GGPLOT2的开发版本'ggplotly()' 与安装它:'devtools :: install_github( '哈德利/ GGPLOT2')'” – DataJack
我更新GGPLOT2和警告都没有了。感谢您的建议。但它并没有解决这个问题。 – Jim