0

I have a plot that I show in a box and I want to modify the size of the box, but the plot is bigger than the box.How can I modify both of them, so that the plot remains and fits the box?

#in ui.r
 box(
                  title = "Veniturile si cheltuielile",
                  status = "primary",
                  solidHeader = TRUE,
                  collapsible = TRUE,
                  plotOutput("ven_vs_chelt")
                )




#in server.r
 output$ven_vs_chelt <- renderPlot({
    ggplot(ven_ch, aes(x=ven_ch$ani_tot, y=ven_chelt, fill=tip)) +
      geom_bar(stat="identity", position=position_dodge(), colour="black") +
      xlab("An") + ylab("Valoare venituri si cheltuieli(lei)") +
      scale_fill_manual(values=c("#F78181", "#81F79F"))
  })
1
  • A few hints: 1) To get Responses you should make your Code reproducible, see stackoverflow.com/questions/5963269/…. 2) More general you are looking for a dynamic UI element. Therefore you should take a look into renderUI(). If you have further questions go for 1) and we can help. Commented Oct 23, 2017 at 11:24

1 Answer 1

2

You can modify a size of the plot. So that it would fit in the box. You can do like this to modify a plot size:

## In your ui, set the width to 100% in your plotOutput
 plotOutput(outputId = "ven_vs_chelt",  width = "100%")

## In your server, you specify height and width to make a plot fit in your box. You should play with height and width. So that it would fit in the box.
output$ven_vs_chelt <- renderPlot({
ggplot(ven_ch, aes(x=ven_ch$ani_tot, y=ven_chelt, fill=tip)) +
  geom_bar(stat="identity", position=position_dodge(), colour="black") +
  xlab("An") + ylab("Valoare venituri si cheltuieli(lei)") +
  scale_fill_manual(values=c("#F78181", "#81F79F"))
}, height = 300, width = 450)
Sign up to request clarification or add additional context in comments.

1 Comment

To be responsive, you need to get the window size. I think you should go through this question to get plot more responsive: Responsive Plot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.