簡體   English   中英

如何從 ggplot2 圖形 R Shiny 中刪除白色背景?

[英]How to remove White background from ggplot2 graph R Shiny?

我正在使用 Shiny 中的 ggplot2 繪制圖表。但是,plot 周圍存在白色背景,我無法將其刪除。 這是我所指的圖像。

在此處輸入圖像描述

是否可以刪除圖形周圍的白色背景? 我試過讓它透明,但這也不起作用。

        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")))

像這樣的代碼

+ theme(panel.background = element_rect(fill = "transparent",colour = NA))

不起作用,因為白色區域不是背景的一部分。 有人對此有任何解決方案嗎?

您可以嘗試將plot.background設置為透明。

+ theme(plot.background = element_rect(fill = "transparent", colour = NA))

或者您可以將您的背景與您的 shiny 背景相匹配。

+   theme(plot.background = element_rect(fill = "#ECF0F5"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM