Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny: Removing ggplot2 background to make it transparent

Tags:

r

ggplot2

shiny

I want to have my ggplots on R Shiny Server have transparent. My ui.R for plotting is as follows:

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

in the server.R my plotting function is as follows:

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

and where it's called:

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

But the graph rendered still has a white background and I want it to be transparent, not white. How do I achieve this? I have attached an image with an arrow showing the plot. My shiny server application. Note the pie chart has a white background and I want it to be transparent

How do i change this background? Please help me.

like image 298
Timothy Tuti Avatar asked Jun 17 '13 16:06

Timothy Tuti


1 Answers

As @baptiste indicated, you also need to pass bg="transparent" to the renderPlot call:

renderPlot({
  ...
}, bg="transparent")
like image 56
Joe Cheng Avatar answered Oct 20 '22 05:10

Joe Cheng