【问题标题】:How to create a bar chart with a fixed y-axis value in Shiny?如何在 Shiny 中创建具有固定 y 轴值的条形图?
【发布时间】:2021-10-26 22:14:48
【问题描述】:

我刚刚学习了 Shiny 一个星期。我检查了ggplot2的功能,但直到现在我还没有找到解决方案。 现在输出条形图如下所示:

每当我更改滑块的值时,图表也会发生变化,但对于它的 y 轴,我希望它的值始终是固定的(例如 0 到 20000)。

现在我滑动滑块后,它会自动按比例变化(例如0到6000)。在这种情况下,用户不会意识到数据发生了多大的变化。

这是我的情节代码的一部分:

    q=ggplot(meantb_bar,aes(x = yi, y = Error_Square))+ 
      
      geom_bar(stat = "identity",fill="deepskyblue3") +

      labs(x = "yi", y = "(y_i-y^)^2")+ #useless for this question

      geom_text(aes(label = Error_Square)) #useless for this question

     ggplotly(q,width=500)

【问题讨论】:

  • ggplot2::coord_cartesian(ylim=c(0,20000))? (将其添加到您的 ggplot(.) 序列中。)

标签: r shiny shinydashboard shiny-server shinyapps


【解决方案1】:

可以使用ggplot的ylim来固定y范围:

q=ggplot(meantb_bar,aes(x = yi, y = Error_Square))+ 
      
      geom_bar(stat = "identity",fill="deepskyblue3") +

      labs(x = "yi", y = "(y_i-y^)^2")+ #useless for this question

      geom_text(aes(label = Error_Square)) +#useless for this question 
      ylim(0, 20000)

     ggplotly(q,width=500)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多