简体   繁体   English

当我使用我的Shiny小部件时,我的ggplot会调整大小:如何阻止它?

[英]My ggplot resizes as I use my Shiny widgets: how to stop this?

The nice thing about using a radiobutton or a slider in an interactive plot is the ability see how output values change as you expand, restrict, or otherwise modify your input values. 在交互式绘图中使用单选按钮或滑块的好处是能够查看输出值在展开,限制或以其他方式修改输入值时如何变化。

With this in mind, it seems natural to keep the size of the plot on the screen constant, AND keep the scale of the x and y axis constant. 考虑到这一点,似乎很自然地保持屏幕上绘图的大小不变,并保持x和y轴的比例不变。

In my case, as the selection of points in my bubbleplot change, the dimensions of the ggplot change; 就我而言,随着我的气泡图中点的选择发生变化,ggplot的尺寸发生了变化; that is, the x and y axis shrink or expand to best accommodate data, and/or the physical size on the screen changes. 也就是说,x和y轴缩小或扩展以最佳地容纳数据,和/或屏幕上的物理尺寸改变。 This distorts the radius of my bubbles, stretching or squeezing them. 这会扭曲我的气泡半径,拉伸或挤压它们。

In an attempt to solve this, I've looked at the 2 obvious places: 为了解决这个问题,我看了两个显而易见的地方:

mainPanel(
      tabsetPanel(
        tabPanel("Plot", plotOutput("bubbleplot")), height=1000, width=800))

...which initially sets the height and width, but this doesn't stay fixed as widgets are activated, and... ...最初设置高度和宽度,但是当窗口小部件被激活时,这不会保持固定,并且......

output$bubbleplot <- renderPlot({
  print(getPlot(df, <inputs>))
  }, 
  width = 1000,
  height = 800
)

...which does the same as above: looks good initially, but doesn't serve as a global control on the length of the x and y axis. ...与上述相同:最初看起来很好,但不能作为x和y轴长度的全局控制。

Excuse me for being bold, but it seems like what I'm talking about could be a very, very common topic for people using Shiny -- I guess I'm surprised this simple task is so difficult, and/or this isn't addressed in the Shiny package. 请原谅我是大胆的,但似乎我所说的对于使用Shiny的人来说可能是一个非常非常常见的主题 - 我想我很惊讶这个简单的任务是如此困难,和/或这不是在Shiny包中解决。

How do I fix the dimensions of plot in Shiny, that stays fixed as I interact with the plot? 如何修复Shiny中的绘图尺寸,当我与绘图交互时保持固定?

Thanks for reading this. 感谢您阅读本文。

As far as the axis scales are concerned, you need to define them within the ggplot function: 就轴刻度而言,您需要在ggplot函数中定义它们:

# assuming inside your getPlot() function there's a ggplot() call
g <- ggplot(data) + geom_whatever(etc)
g <- g + ylim(minY,maxY) + xlim(minX,maxX)
g

More info: http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/#setting-range-and-reversing-direction-of-an-axis 更多信息: http//www.cookbook-r.com/Graphs/Axes_ ( ggplot2)/# setting- range-and- reversing- direction-of-an- axis

Related: I would also like to know how to fix the size of the plot. 相关:我也想知道如何修复情节的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 闪亮没有像我期望的那样显示我的ggplot - Shiny not displaying my ggplot as I'd expect 如何停止ggplot自动排列图表? - how do I stop ggplot automatically arranging my graph? 如何让闪亮的代码中的两个小部件同时工作? - How can I get both widgets in my shiny code to work simultaneously? 如何停止 ggplot 交换我的样本顺序? - How to stop ggplot swapping the order of my samples? 如何在R Shiny中增加ggplot2图形的绝对大小? - How can I increase the absolute size of my ggplot2 graphs in R Shiny? 我的第一个 R Shiny ,我如何将 selectinput 与 renderplot(ggplot) 结合起来? - My first R Shiny , how to am i combine selectinput with renderplot(ggplot)? 如何在 R 的 Shiny 中应用 actionButton 来更新我的 ggplot? - How to apply the actionButton to update my ggplot in Shiny in R? 当我使用fileInput插入我的数据集时,包含在闪亮应用程序中的ggplot2图中的注释文本不起作用 - Annotate text in ggplot2 plot ,included in a shiny app, does not work when I use fileInput to insert my dataset 如何让我的 R Shiny 应用程序停止获取变量的无效类型(列表)? - How do I get my R Shiny app to stop getting an invalid type (list) for a variable? 如何阻止ggplot2将矩阵旋转90度? - How do I stop ggplot2 from rotating my matrix 90 degrees?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM