Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

iris-garden
Copy link
Collaborator

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

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

Copy link
Collaborator

@danking danking left a comment

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
8 checks passed
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.

None yet

3 participants