![](/img/trans.png)
[英]How to get the same colors on different charts (plot_ly, ggplotly)
[英]On shiny app ggplotly() renders half the size of plot_ly(). How to fix that?
当使用ggplotly vs plot_ly在闪亮的应用程序中生成情节时,绘图的宽度小于一半。 这是为什么? 有没有办法解决它,以便ggplotly生成与plot_ly或ggplot2相同宽度的图? 我尝试过使用width参数,但是没有修复它。
闪亮应用程序的输出:
library(shiny)
library(plotly)
library(ggplot2)
ui <- fluidPage(
titlePanel("plotly with shiny"),
mainPanel(
h4("Using ggplotly:"), plotlyOutput("ggplotly", width = "200"),
h4("Using native plotly:"), plotlyOutput("plotly"),
h4("Using ggplot:"), plotOutput("ggplot")
)
)
server <- function(input, output) {
data <- reactive({
d = diamonds[sample(nrow(diamonds), 300),]
})
output$ggplot <- renderPlot({
ggplot(data(), aes(x=carat, y=price, color=price)) + geom_point()
})
output$ggplotly <- renderPlotly({
v = ggplot(data(), aes(x=carat, y=price, color=price)) + geom_point()
ggplotly(v)
})
output$plotly <- renderPlotly({
plot_ly(data(), x = ~carat, y = ~price, color = ~price)
})
}
shinyApp(ui = ui, server = server)
不要使用plotlyOutput
的参数width
,并使用ggplotly
的一个:
ggplotly(v, width=800)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.