这里是我的代码:ggiraph情节不调整大小以适应页面
library(shiny)
library(ggplot2)
library(ggiraph)
df <- data.frame(achseX = LETTERS[1:24], achseY = 1:24, facetX = as.factor(rep(1:4, each = 6)))
server <- function(input, output) {
output$ggplot <- renderPlot({
ggplot(data = df) + geom_bar_interactive(aes(tooltip = achseY, x = achseX, y = achseY), stat = "identity") +
theme_minimal() + facet_grid(.~ facetX, scales = "free_x")
})
output$plot <- renderggiraph({
gg <- ggplot(data = df) + geom_bar_interactive(aes(tooltip = achseY, x = achseX, y = achseY), stat = "identity") +
theme_minimal() + facet_grid(.~ facetX, scales = "free_x")
return(ggiraph(code = print(gg), selection_type = "multiple", zoom_max = 4,
hover_css = "fill:#FF3333;stroke:black;cursor:pointer;",
selected_css = "fill:#FF3333;stroke:black;"))
})
}
ui <- fluidPage(
"GGPLOT2:",
plotOutput("ggplot"),
"GGIRAPH:",
ggiraphOutput("plot", width = "500px", height = "1000px")
)
shinyApp(ui = ui, server = server)
正如你可以在代码中看到,第一barplot是ggplot
按照它应该的方式工作。它对网站有响应并具有矩形格式。 ggiraph
保持方形格式,而不适合页面。
我怎样才能让ggiraph看起来像ggplot?
我尝试了几种宽度和高度参数的组合,还包括width = "auto"
和height = "auto"
。这使ggiraph适合页面,但仍然以方形格式。