【问题标题】:R Shiny: Removing ggplot2 background to make it transparentR Shiny:删除 ggplot2 背景以使其透明
【发布时间】:2013-06-13 16:33:19
【问题描述】:

我想让我在 R Shiny Server 上的 ggplots 透明。我用于绘图的 ui.R 如下:

  plotOutput("malPie", width="95%")

在server.R中我的绘图功能如下:

 c <- ggplot(dataFrame, aes(x=factor(nrow(dataFrame)),fill=graphX),environment=environment()) + geom_bar(width = 1)
    print(c + coord_polar(theta = "y")+ xlab(xLabel)+ylab(yLabel)+ labs(fill=legendTitle)+ theme(
    panel.grid.minor = element_blank(), 
    panel.grid.major = element_blank(),
    panel.background = element_blank(),
    plot.background = element_blank()
   ))

以及它的名称:

  sub <- data
  sub <- subset(sub,sub$mal_tested=="1")
  drawGraph("pie",sub,factor(sub$mal_tested_pos),"Malaria Tests Done",NULL,"Malaria Tested Positive","Malaria")

但是渲染的图形仍然有白色背景,我希望它是透明的,而不是白色的。我如何实现这一目标?我附上了一张带有箭头的图像,显​​示了情节。

如何更改此背景?请帮帮我。

【问题讨论】:

  • ?renderPlot 建议您可以将背景颜色传递给闪亮似乎正在使用的 png 设备。默认背景颜色确实取决于 R 中的设备,IIRC pdf 和 png 具有不同的默认值。
  • 只是想提一下,从截图中我可以看到,您的闪亮应用看起来非常漂亮!代码是开源的吗?我一直在寻找复杂的闪亮应用程序。

标签: r ggplot2 shiny


【解决方案1】:

正如@baptiste 所指出的,您还需要将bg="transparent" 传递给renderPlot 调用:

renderPlot({
  ...
}, bg="transparent")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 2011-12-06
    • 2014-05-07
    • 2020-11-07
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多