Skip to content

[query/ggplot] Shows legend group for single-value columns - #13113

Merged
danking merged 1 commit into
hail-is:mainfrom
iris-garden:query/ggplot/single-value-legend-group
Jun 9, 2023
Merged

[query/ggplot] Shows legend group for single-value columns#13113
danking merged 1 commit into
hail-is:mainfrom
iris-garden:query/ggplot/single-value-legend-group

Conversation

@iris-garden

@iris-garden iris-garden commented May 24, 2023

Copy link
Copy Markdown
Contributor

CHANGELOG: hail.ggplot.geom_point now displays a legend group for a column even when it has only one value in it.

Currently, if a column with only one value in it is passed to either the color or the shape aesthetic for geom_point, the generated legend will not include a group with a single entry for that aesthetic. However, R's ggplot2 library in the same situation includes such a legend group.

This change brings our ggplot implementation into line with R's ggplot2 in that regard.

For example, this code:

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="good")
fig = (
    ggplot(ht, aes(x=ht.idx, y=ht.squared))
    + geom_point(aes(color=ht.even, shape=ht.threeven))
)
fig.show()

generates a plot legend like this on main:

Screenshot 2023-05-24 at 13 19 49

but generates one like this on this branch:

Screenshot 2023-05-24 at 13 19 16

@iris-garden
iris-garden force-pushed the query/ggplot/single-value-legend-group branch from d5fa702 to fb456f5 Compare May 24, 2023 17:21

@danking danking left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iris-garden
iris-garden force-pushed the query/ggplot/single-value-legend-group branch from fb456f5 to 2231efe Compare June 5, 2023 14:33
@iris-garden
iris-garden force-pushed the query/ggplot/single-value-legend-group branch from 2231efe to f131495 Compare June 5, 2023 20:01
CHANGELOG: `hail.ggplot2.geom_point` now displays a legend group for a
column even when it has only one value in it.

Currently, if a column with only one value in it is passed to either the
`color` or the `shape` aesthetic for `geom_point`, the generated legend
will not include a group with a single entry for that aesthetic.
However, R's ggplot2 library in the same situation includes such a
legend group.

This change brings our ggplot implementation into line with R's ggplot2
in that regard.

For example, this code:

```python
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="good")
fig = (
    ggplot(ht, aes(x=ht.idx, y=ht.squared))
    + geom_point(aes(color=ht.even, shape=ht.threeven))
)
fig.show()
```

generates a plot legend like this on `main`:

<legend>

but generates one like this on this branch:

<legend>
@danking
danking merged commit bf814b6 into hail-is:main Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants