Skip to content

Turn ha and va into aesthetics for geom_text() - #325

Merged
has2k1 merged 1 commit into
has2k1:masterfrom
jeroenjanssens:master
Dec 16, 2019
Merged

has2k1 merged 1 commit into
has2k1:masterfrom
jeroenjanssens:master

Conversation

@jeroenjanssens

Copy link
Copy Markdown
Contributor

While recreating the following figure of Section 28.3 from R for Data Science:

I noticed that ha and va are not aesthetics but parameters. According to the documentation, this is because of a limitation in Matplotlib (see matplotlib/matplotlib#1181). Unless I fail to fully understand the issue, I believe that this small change fixes it. At least I was able to reproduce the above figure with the following code:

from plotnine import *
import pandas as pd
from itertools import product

has = ["left", "center", "right"]
vas = ["top", "center", "bottom"]
xs = [0, 0.5, 1]
ys = [1, 0.5, 0]

df = pd.DataFrame([{"x": xs[x],
                    "y": ys[y],
                    "ha": has[x],
                    "va": vas[y],
                    "label": f"ha=\"{has[x]}\"\nva=\"{vas[y]}\""}
                   for x, y in product(range(3), repeat=2)])

ggplot(df, aes("x", "y")) +\
geom_point(colour="grey", size=5) +\
geom_point(size=0.5, colour="red") +\
geom_text(aes(label="label", ha="ha", va="va"), size=14) +\
labs(x=None, y=None)

download (4)

Please forgive me for not yet taking care of the deprecated terms "hjust" and "vjust". I wasn't able to quickly figure out how to treat those as aliases in the case of aesthetics.

@has2k1

has2k1 commented Nov 6, 2019

Copy link
Copy Markdown
Owner

This PR also raises the issue that the aesthetics are not documented (with descriptions). So far, I think all the aesthetics have been self-descriptive, but va and ha are not.

@has2k1

has2k1 commented Dec 16, 2019

Copy link
Copy Markdown
Owner

This PR also raises the issue that the aesthetics are not documented (with descriptions). So far, I think all the aesthetics have been self-descriptive, but va and ha are not.

I was wrong. There is a provision for documenting them as some stats do. I had forgotten about it!

@has2k1
has2k1 merged commit c9f13c3 into has2k1:master Dec 16, 2019
@has2k1

has2k1 commented Dec 16, 2019

Copy link
Copy Markdown
Owner

@jeroenjanssens. Thanks. I will handle the documentation and the old parameters names.

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.

2 participants