How to R plot legend with transparent background when using plot()
function ?
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”).
Therefore, we can use bty="n" with the legend function and it will remove the border of the legend.
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.
Use: bg="transparent" in
legend()
Such as:
legend("right",bg="transparent",col=c(as.numeric(unique(df$group2))),cex=0.5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With