Forum Discussion
R Visual with transparent background
- 7 years ago
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)
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")
gBut as you can see I still have a white background:
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
- ross279 years agoAdvocate II
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- PythonChan9 years agoNew 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, [email protected] ,please.
Thank you so much