Skip to content

Fix geom_rug + coord_flip #2988

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

Merged
merged 2 commits into from
Nov 11, 2018
Merged

Conversation

has2k1
Copy link
Contributor

@has2k1 has2k1 commented Nov 9, 2018

The rugs in geom_rug are drawn along an axis depending the
sides parameter. Since the coordinate system does not alter
the geom parameters, the geom has to alter any parameters
that determine where the geoms are plotted.

fixes #2987


library(ggplot2)

df <- data.frame(x = 1:10, y = (1:10)^3)
g <- ggplot(df, aes(x, y)) + geom_point() + geom_rug(sides = 'l')

# Normal plot
g

# The rugs are flipped
g + coord_flip()

Created on 2018-11-09 by the reprex package (v0.2.1)

The rugs in `geom_rug` are drawn along an axis depending the
`sides` parameter. Since the coordinate system does not alter
the `geom` parameters, the `geom` has to alter any parameters
that determine where the geoms are plotted.

fixes tidyverse#2987
Copy link
Member

@clauswilke clauswilke left a comment

Choose a reason for hiding this comment

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

Thanks! Overall this looks correct to me.

@@ -66,6 +66,10 @@ GeomRug <- ggproto("GeomRug", Geom,
rugs <- list()
data <- coord$transform(data, panel_params)

if (inherits(coord, 'CoordFlip')) {
Copy link
Member

Choose a reason for hiding this comment

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

I wish we wouldn't test for capabilities by testing for inheritance, but this is how it's done for CoordFlip all over the ggplot2 code base, so I guess it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first instinct was to use is(), but it was not used anywhere in the coord base.

Copy link
Member

Choose a reason for hiding this comment

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

What I meant was other coord features are queried by asking the coord, e.g. coord$is_free(). So it would probably make sense to introduce coord$is_flip(). But that's for a different PR.

@@ -66,6 +66,10 @@ GeomRug <- ggproto("GeomRug", Geom,
rugs <- list()
data <- coord$transform(data, panel_params)

if (inherits(coord, 'CoordFlip')) {
sides <- chartr('tblr', 'rlbt', sides)
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding a comment to this line explaining what's happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a comment to the block.

@clauswilke
Copy link
Member

@hadley This looks good to me. Any concerns from you?

@clauswilke clauswilke merged commit 67ab63d into tidyverse:master Nov 11, 2018
@lock
Copy link

lock bot commented May 10, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators May 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

geom_rug and coord_flip do not work together
3 participants