Skip to content

problem with test for monotonous transformation (secondary axis)? #2008

Closed

Description

@hansvancalster
testdat <- data.frame(x = runif(11),
                      y = seq(0,1,0.1))

# NOT OK
ggplot(data = testdat, aes(x = x, y = y)) + 
  geom_point() + 
  scale_y_continuous(sec.axis = sec_axis(trans = ~ .^0.5))

#  OK
ggplot(data = testdat[testdat$y > 0, ], aes(x = x, y = y)) + 
  geom_point() + 
  scale_y_continuous(sec.axis = sec_axis(trans = ~ .^0.5))

Activity

  1. hadley commented on Jan 25, 2017

    @hadley
    Member

    I've cleaned up the issue title/comment thread to focus on key components of problem. Thanks for the correspondence so far 😄

  2. added
    bug
    on Jan 25, 2017
  3. hadley commented on Jan 27, 2017

    @hadley
    Member

    This is the same root cause as #980 — the problem is that the transformation has to be monotonous over the range of the scales, not the range of the data. You can work around it by eliminating the scale expansion:

    library(ggplot2)
    df <- data.frame(x = runif(5), y = seq(0,1, length = 5))
    
    ggplot(df, aes(x, y)) + 
      scale_y_continuous(
        sec.axis = sec_axis(trans = ~ .^0.5), 
        expand = c(0, 0)
      )

  4. hansvancalster commented on Feb 2, 2017

    @hansvancalster
    Author

    Thanks! That explains what happened and the work-around is OK.

  5. locked as resolved and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugscales 🐍

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions