您可以在运行 ggplotly 后更改绘图属性。不确定你的意思是否是调整布局,但如果是这样,那么我无法复制你的问题,因为它超过 500 绝对没问题。
例如,在这种情况下:
pt<-ggplotly(p) %>% layout(dragmode = "select")
# have a look to all attributes
str(pt)
#Specifically height is
pt$height<-700
您可以测试差异:plotly为500,ggplotly为700(不要在中设置高度plotlyOutput
itself)
output$plot <- renderPlotly({
# use the key aesthetic/argument to help uniquely identify selected observations
key <- row.names(mtcars)
if (identical(input$plotType, "ggplotly")) {
p <- ggplot(mtcars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) +
geom_point()
pt<- ggplotly(p) %>% layout(dragmode = "select")
pt$height<-700
pt
# ggplotly(p) %>% layout(dragmode = "select")
} else {
plot_ly(mtcars, x = ~mpg, y = ~wt, key = ~key) %>%
layout(dragmode = "select",height = 500)
}
})
编辑:ggplotly和plotly具有相同的大高度,并且不重叠文本输出,前提是ui中的高度大于ggplotly布局参数中的高度:
output$plot <- renderPlotly({
key <- row.names(mtcars)
if (identical(input$plotType, "ggplotly")) {
p <- ggplot(mtcars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select", height=800)
} else {
plot_ly(mtcars, x = ~mpg, y = ~wt, key = ~key) %>%
layout(dragmode = "select")
}
})
plotlyOutput("plot", height = 800)