animint icon indicating copy to clipboard operation
animint copied to clipboard

stroke-opacity and fill-opacity aesthetics

Open srvanderplas opened this issue 9 years ago • 7 comments

Specify stroke-opacity and fill-opacity separately (allowing rectangles to have no fill but still have a border, etc.). These options are available in d3 but are not currently ggplot2 aesthetics.

srvanderplas avatar Nov 19 '14 02:11 srvanderplas

Looks like this is on the TODO list, but to be honest, I think it is more transparent if we translate the TODO list to issues. Thoughts @tdhock?

cpsievert avatar Nov 19 '14 03:11 cpsievert

Susan, if I understand correctly you would like to specify the transparency/opacity separately for stroke/color and fill? What aethetics do you suggest? aes(alpha_color=1/2, alpha_fill=3/4)? or aes(stroke_opacity=1/2, fill_opacity=3/4)? Can you please provide a concrete example with code and data?

In fact, there is not yet a TODO for that. The TODO that Carson referenced is about aes for different selection states. More generally I think it is fine to move some TODOs to GitHub issues, so go ahead and do that for the ones you think are important.

tdhock avatar Nov 19 '14 14:11 tdhock

d3 has options for stroke-opacity and fill-opacity, which I ran into recently because I needed the rectangular outline but not the inside. I worked around it using css and the id aesthetic (awesome, btw - but doesn't work as a constant aesthetic per geom). I'm not particular on the syntax, but it would be nice to be able to specify both options separately. For consistency with R syntax, alpha_color and alpha_fill are probably the best choice.

I'm working on a minimal example of where this would be useful. Will post soon.

On Wed, Nov 19, 2014 at 8:22 AM, Toby Dylan Hocking < [email protected]> wrote:

Susan, if I understand correctly you would like to specify the transparency/opacity separately for stroke/color and fill? What aethetics do you suggest? aes(alpha_color=1/2, alpha_fill=3/4)? or aes(stroke_opacity=1/2, fill_opacity=3/4)? Can you please provide a concrete example with code and data?

In fact, there is not yet a TODO for that. The TODO that Carson referenced is about aes for different selection states. More generally I think it is fine to move some TODOs to GitHub issues, so go ahead and do that for the ones you think are important.

— Reply to this email directly or view it on GitHub https://github.com/tdhock/animint/issues/32#issuecomment-63646295.

srvanderplas avatar Nov 19 '14 14:11 srvanderplas

http://bl.ocks.org/srvanderplas/raw/ecfe137aab991c9eee8d/

This gist contains an example where this feature would be very useful, but is not currently intuitive. A workaround is possible using the aesthetic id="label" and css, but it would be more intuitive to be able to specify the fill and stroke opacity aesthetics within R. Currently, there are cases where it is reasonable to use a rectangle selector (tallrect, for example) but selecting an object distorts other aesthetics because there is no way to turn the fill off entirely.

srvanderplas avatar Nov 19 '14 15:11 srvanderplas

For the example you gave I think there is a workaround: have you tried fill="transparent" or fill=NA?

But yes it would still be nice to specify different opacity values for fill and color.

tdhock avatar Nov 19 '14 16:11 tdhock

The first plot is fill=NA. fill=transparent works, though. I messed around with fill="none", etc. last night, but didn't try "transparent".

http://bl.ocks.org/srvanderplas/raw/b7ee3272513f79c93d9a/

Still would be good to have the d3 aesthetics that aren't available in R supported, though.

On Wed, Nov 19, 2014 at 10:01 AM, Toby Dylan Hocking < [email protected]> wrote:

For the example you gave I think there is a workaround: have you tried fill="transparent" or fill=NA?

But yes it would still be nice to specify different opacity values for fill and color.

— Reply to this email directly or view it on GitHub https://github.com/tdhock/animint/issues/32#issuecomment-63662952.

srvanderplas avatar Nov 19 '14 16:11 srvanderplas

looks like in ggplot2 v2.0

alpha now affects both fill and colour aesthetics (#1371).

https://github.com/hadley/ggplot2/blob/master/NEWS.md#default-appearance

tdhock avatar Dec 20 '15 14:12 tdhock