You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Function colour_ramp() should respect transparency by default #108
The function colour_ramp() has the option to ramp RGBA colors instead of RGB colors. However, by default, this option is switched off, and the function removes any alpha values that may be attached to the colors it is given.
This seems to be an unusual default setting. If somebody goes to the effort of adding alpha values to colors, I would assume they want those respected. Also, this creates inconsistency between discrete and continuous color scales. Discrete scales respect alpha value, continuous ones do not.
Reproducible example: First a case using a discrete color scale.
I am trying to use this to change the transparency of colour and fill of geom_polygon, but noticed that the solution above affects colour and fill differently. The difference is only small, but leads to very ugly graphs with tightly spaced polygons (e.g. maps)
It is not the case that color and fill are affected differently. Instead, the lines are drawn on top of the fill area and therefore those regions appear darker. We can exaggerate this effect by making the lines thicker. And we can avoid it by removing the lines altogether.
library(ggplot2)
# make line thicker to highlight the problem
ggplot(iris, aes(Sepal.Length, fill= as.numeric(Species), colour= as.numeric(Species), group=Species)) +
geom_density(size=5) +
scale_fill_gradientn(colors= c("#00FF00FF", "#008000B0", "#0000FF20")) +
scale_colour_gradientn(colors= c("#00FF00FF", "#008000B0", "#0000FF20"))
Yes, that's a fundamental limitation of the current R graphics architecture, and it's the reason why my gradient geoms from the ggridges package don't allow transparency.
Activity
update news. closes r-lib#108
lukasjonkers commentedon Oct 19, 2018
I am trying to use this to change the transparency of colour and fill of
geom_polygon, but noticed that the solution above affects colour and fill differently. The difference is only small, but leads to very ugly graphs with tightly spaced polygons (e.g. maps)Any clue why this might be and how to fix it?
clauswilke commentedon Oct 20, 2018
It is not the case that color and fill are affected differently. Instead, the lines are drawn on top of the fill area and therefore those regions appear darker. We can exaggerate this effect by making the lines thicker. And we can avoid it by removing the lines altogether.
Created on 2018-10-19 by the reprex package (v0.2.1)
lukasjonkers commentedon Oct 20, 2018
I see, should have thought about that myself. That makes it hard to use transparency and get rid of the blank/white lines when plotting polygons.
Because I seem to need the lines for that purpose.
Code from here
clauswilke commentedon Oct 20, 2018
Yes, that's a fundamental limitation of the current R graphics architecture, and it's the reason why my gradient geoms from the ggridges package don't allow transparency.