简体   繁体   中英

how can I control the alpha setting in R when using the points function?

I'm creating an interactive Shiny app -- I have a widget (a slider) that retrieves an alpha parameter from the user. The user can select an alpha value between 0.0 and 1.0

My app is all set up, however, and when I went back to add the alpha to the plot, I am shocked to see that when adding points to a plot in R, the points function doesn't have a parameter for alpha.

I can create nice points here:

points(DF$x_values, DF$y_values, pch=20, cex=2, col="springgreen4")

but I can't add any sort of alpha parameter to the call!

Surely I'm not the only person to find this. Does anyone know the reasoning behind this lack of functionality, or even better...has anyone found a good work around?

You can use rgb() to specify color so you can control alpha:

plot(1:5, cex = 0)
points(1:5, pch=20, cex=2, col = rgb(0, 1, 0, c(0.1,0.2, 0.3, 0.4, 0.5)))

In your example:

points(DF$x_values, DF$y_values, pch=20, cex=2, col = rgb(0, 1, 0, alpha))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM