Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R plot legend with transparent background

How to R plot legend with transparent background when using plot() function ?

like image 358
Qbik Avatar asked Apr 29 '16 13:04

Qbik


People also ask

How do you make a transparent graph in R?

Make transparent colors in RThe rgb() command is the key: you define a new color using numerical values (0–255) for red, green and blue. In addition, you set an alpha value (also 0–255), which sets the transparency (0 being fully transparent and 255 being “solid”).

How do I remove the legend border in R?

Therefore, we can use bty="n" with the legend function and it will remove the border of the legend.

How do I change the size of the legend box in R?

To change the legend size of the plot, the user needs to use the cex argument of the legend function and specify its value with the user requirement, the values of cex greater than 1 will increase the legend size in the plot and the value of cex less than 1 will decrease the size of the legend in the plot.


1 Answers

Use: bg="transparent" in

legend()

Such as:

legend("right",bg="transparent",col=c(as.numeric(unique(df$group2))),cex=0.5)
like image 53
Shicheng Guo Avatar answered Sep 19 '22 20:09

Shicheng Guo