Reputation: 1162
I am plotting graphs using ggplot2 in Shiny. However, a white background exists around the plot, which I cannot remove. Here is an image of what I am referring to.
Is it possible to remove this white background around the graph? I've tried making it transparent, but that is not working, either.
output$descrHistPlot <- renderPlot(ggplot(variableDataDescrPlots$dataMelted, aes(y = value)) + geom_histogram(bins = descrPlotsBins$bins, fill = "grey", color = "black") +
facet_wrap(~variable) + coord_flip() + ggtitle(paste0("Histogram of ", input$menuDescrPlots[[1]], " Variables")) +
theme(plot.title = element_text(size = rel(1.50), face = "bold", hjust = 0.5)) +
theme(axis.title = element_text(size = rel(1.25), face = "bold")) +
theme(axis.text = element_text(size = rel(1.25), face = "bold")) +
theme(panel.grid.major = element_line(color = "white"), panel.background = element_rect(fill = "lightblue"),
panel.border = element_rect(color = "blue", fill = NA)) +
theme(strip.text.x = element_text(size = 11, colour = "blue", face = "bold")))
Code like this
+ theme(panel.background = element_rect(fill = "transparent",colour = NA))
does not work, as that white area is not part of the background. Does anyone have any solutions to this?
Upvotes: 0
Views: 1651
Reputation: 3671
You can try setting the plot.background
to transparent.
+ theme(plot.background = element_rect(fill = "transparent", colour = NA))
Or you can match your background to your shiny background.
+ theme(plot.background = element_rect(fill = "#ECF0F5"))
Upvotes: 3