Forum Discussion

ross27's avatar
ross27
Advocate II
9 years ago
Solved

R Visual with transparent background

Is it possible to create an R-Visual with a transparent background i.e. so that you can see an image added to the page background behing the plot the R-Visual generates?

 

Specifically I'm using ggplot2 and setting the fill of both plot.background andpanel.background to "transparent", but there still seems to be a white background between this and the background I can control through the PBI format options.

  • I don't know whether this will work with ggplot2 but in a visual I made based on the fmsb package I was able to work around this issue by using the par() function before the plotting was called:

     

    # generic par function for graphical elements, call before the plotting
    par(bg="transparent")
    # this is wear the plotting of the visual actually happens radarchart(data)

     

20 Replies

  • I don't know whether this will work with ggplot2 but in a visual I made based on the fmsb package I was able to work around this issue by using the par() function before the plotting was called:

     

    # generic par function for graphical elements, call before the plotting
    par(bg="transparent")
    # this is wear the plotting of the visual actually happens radarchart(data)

     

  • ankitpatira's avatar
    ankitpatira
    Community Champion

    ross27 You can enable R visuals and then under Paintbrush icon set the background property.

     

    • ross27's avatar
      ross27
      Advocate II

      Thanks Ankit.  I do have that option set, but it just produces the result Herbert describes below.

  • v-haibl-msft's avatar
    v-haibl-msft
    Microsoft Employee

    ross27

     

    There is no option in Format pane to make the R visual background to be transparent. Only small part (around the R visual) can be transparent as below.

     

    But we should be able to set bg="transparent" to make it to be transparent like below. Could you please share your R scripts written in the R script editor? Please also take a look at this link to see if it helps.

     

    Best Regards,

    Herbert

    • ross27's avatar
      ross27
      Advocate II

      Thanks Herbert.  This is the final part of my script:

       

      g <- g + theme_void() +
      theme(
          axis.text.x = element_text(angle = 45,size=11,vjust=0.9),
          legend.position="none",
          plot.background = element_rect(fill="transparent", color=NA),
          panel.background = element_rect(fill="transparent", color=NA)
        )
      
      par(bg="transparent")
      
      g

      But as you can see I still have a white background:

       

       

      • v-haibl-msft's avatar
        v-haibl-msft
        Microsoft Employee

        ross27

         

        How about the result if update the script as below? If problem still persists, could you please share your .pbix file?

         

        panel.background = element_rect(fill = "transparent",colour = NA), 
        panel.grid.minor = element_blank(), 
        panel.grid.major = element_blank(),
        plot.background = element_rect(fill = "transparent",colour = NA))
        panel.background = theme_rect(fill = "transparent",colour = NA),
        panel.grid.minor = theme_blank(), 
        panel.grid.major = theme_blank(),
        plot.background = theme_rect(fill = "transparent",colour = NA)

        Best Regards,

        Herbert

  • Hi

    Do you solve the problem?

    I have the same issue,too.

    If you have already solved the problem, could you send me the method by email,  [email protected] ,please.

    Thank you so much

  • Hi

    Do you solve the problem?

    I have the same issue,too.

    If you have already solved the problem, could you send me the method by email,  [email protected] ,please.

    Thank you so much

     

     

    I'm sorry

    just try again

  • Hi

    Do you solve the problem?

    I have the same issue,too.

    If you have already solved the problem, could you send me the method by email,  [email protected] ,please.

    Thank you so much

     

     

    I'm sorry

    just try again

    • ross27's avatar
      ross27
      Advocate II

      No, sorry.  I never resolved this

    • Anonymous's avatar
      Anonymous
      Not applicable

      Were you able to figure this out?

  • jfallt's avatar
    jfallt
    Frequent Visitor

    I know this is an old thread but set the fill and the color of the element_rect layer equal to the background color

    i.e. plot.background = element_rect(fill = "black", color = "black")
     
    Example Below:
     
    • ross27's avatar
      ross27
      Advocate II

      Hi jfallt , the problem is that the page background is an image.  I've not tested in a while, but have you been able to set the fill to transparent?

      • jfallt's avatar
        jfallt
        Frequent Visitor

        ross27 if you set it to "transparent" it returns a white background.