cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ross27
Advocate I
Advocate I

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.

1 ACCEPTED SOLUTION
arvidb
New Member

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)

 

View solution in original post

19 REPLIES 19
arvidb
New Member

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)

 

View solution in original post

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:
 
RVisual.jpg

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
Frequent Visitor

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

PythonChan
New Member

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,  cy-song@163.com ,please.

Thank you so much

 

 

I'm sorry

just try again

Were you able to figure this out?

Hi,

 

Could you figure this out?

No, I never found a solution for this

Is there a way this can be reported to Microsoft, because this really makes my visual not usable?

No, sorry.  I never resolved this

PythonChan
New Member

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,  cy-song@163.com ,please.

Thank you so much

 

 

I'm sorry

just try again

PythonChan
New Member

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,  cy-song@163.com ,please.

Thank you so much

v-haibl-msft
Microsoft
Microsoft

@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.

R Visual with transparent background_1.jpg

 

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.

R Visual with transparent background_2.jpg

 

Best Regards,

Herbert

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:

 

lollipop.jpg

 

@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

I still have the same issue.  I can't see how to upload a pbix, but here's the full code behind the visual.

 

"audience" is a text column providing the labels for my x-axis

"overlap" is an integer used to size the data points

"gindex" is a decimal, plotted on the y-axis

"indexColor" is either 1 or -1 and is used to colour the circles.

 

dataset <- data.frame(audience, overlap, gindex, indexColor)

library(ggplot2)

rescale <- function(x,over=dataset$overlap,minSize=5,maxSize=40) {
  x <- log(x)
  over <- log(over)
  
  rng <- range(over)
  
  ((x-rng[1])/(rng[2]-rng[1])) * (maxSize-minSize) + minSize
  
}

g <- ggplot(dataset,aes(audience,gindex))

#Lines

g <- g + geom_segment(aes(xend=audience,yend=0),linetype="dashed",size=1.5)

#Circles

g <- g + geom_point(aes(size=rescale(overlap),colour=indexColor)) +
  scale_size_identity() +
  scale_colour_gradientn(colours=c("#FF0000","#00FF00"))

#Ensure circles fit at top of plot (20 = maxSize used in rescale()/2) and
# remove gap between y-axis bottom of plot area

g <- g + 
    scale_y_continuous(limits = c(0,max(dataset$gindex)+20), expand = c(0, 0)) 

#Labels for index values
g <- g + geom_text(aes(label=gindex), fontface = "bold")

#Remove unwanted styling,
#   Adjust axis labels
#
g <- g + theme_void() +
theme(
    axis.text.x = element_text(angle = 45,size=11,vjust=0.9),
    legend.position="none",
    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)
  )

par(bg="transparent")

g

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,  cy-song@163.com ,please.

Thank you so much

ankitpatira
Community Champion
Community Champion

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

 

Capture.PNG

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

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are You Ready?

Test your skills now with the Cloud Skills Challenge.

Top Solution Authors