سؤال

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))
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top