hail icon indicating copy to clipboard operation
hail copied to clipboard

[ggplot] add shape aesthetic support to point geom

Open iris-garden opened this issue 2 years ago • 1 comments

Currently, geom_point does not support specifying a point shape via an aesthetic. This change adds support for a shape aesthetic to geom_point. For example, using the following set of commands after this change has been applied produces the graph below. See the plotly documentation for a list of supported point shapes.

import hail as hl
from hail.ggplot import ggplot, aes, geom_point
ht = hl.utils.range_table(10)
ht = ht.annotate(squared=ht.idx ** 2)
ht = ht.annotate(even=hl.if_else(ht.idx % 2 == 0, "yes", "no"))
fig = (
    ggplot(ht, aes(x=ht.idx))
    + geom_point(aes(y=ht.squared, color=ht.even, shape=ht.even))
)
fig.show()

newplot

iris-garden avatar Sep 20 '22 20:09 iris-garden

I tried making a plot with only shape, not color. It should behave the same as color (in the discrete case), only using shapes instead of colors, but right now the legend uses "trace 0" etc. instead of the data values.

I was able to get the category names showing properly in the legend with just shapes by adding a shape_legend -> name mapping to GeomPoint.trace_args, but this caused the shape names to override the color names when using both; I added logic to Geom._add_aesthetics_to_trace_args to concatenate the names with one legend entry per pair of color and shape, which causes the shapes to stop working and a separate color to be assigned to each legend entry.

import hail as hl
from hail.ggplot import ggplot, aes, geom_point
ht = hl.utils.range_table(10)
ht = ht.annotate(squared=ht.idx ** 2)
ht = ht.annotate(even=hl.if_else(ht.idx % 2 == 0, "yes", "no"))
ht = ht.annotate(threeven=hl.if_else(ht.idx % 3 == 0, "good", "bad"))
fig = (
    ggplot(ht)
    + aes(x=ht.idx, y=ht.squared, color=ht.even, shape=ht.threeven)
    + geom_point()
)
fig.show()

newplot(1)

I'm having trouble tracking down why this is happening, so I'll ask for some help with that tomorrow.

iris-garden avatar Sep 22 '22 21:09 iris-garden