Reputation: 12580
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.
In my case, as the selection of points in my bubbleplot change, the dimensions of the ggplot change; that is, the x and y axis shrink or expand to best accommodate data, and/or the physical size on the screen changes. 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.
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.
How do I fix the dimensions of plot in Shiny, that stays fixed as I interact with the plot?
Thanks for reading this.
Upvotes: 3
Views: 1045
Reputation: 727
As far as the axis scales are concerned, you need to define them within the ggplot function:
# 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
Related: I would also like to know how to fix the size of the plot.
Upvotes: 1