Git Product home page Git Product logo

Comments (6)

stefanedwards avatar stefanedwards commented on May 28, 2024 1

from lemon.

stefanedwards avatar stefanedwards commented on May 28, 2024

Update

The root cause is that when turning legends off with d + theme(legend.position='hidden'), our garnish on the axis lines are removed for some reason. I will look into it some more.

Edit: reposition_legend uses the theme function to turn off legends when rendering the remainder of the plot...

from lemon.

stefanedwards avatar stefanedwards commented on May 28, 2024

This is a most excellent issue, you have found, and it has nothing to do with lemon.
It is actually ggplot2 that causes the problem when adding multiple themes, but I am not sure what the expected behaviour should be. I would say, at least not this!

The cause is that axis.line.x inherits from axis.line. When axis.line is element_blank() in theme_minimal() and theme_gray() (to name a few), rendering the following behaves as expected.

d <- ggplot(iris, aes(x = Petal.Width, fill = Species)) + 
  geom_histogram()
d + theme_minimal() + theme(axis.line.x=element_line(linetype='dashed'))

Now add a third theme for hiding the legend,

d + theme_minimal() + theme(axis.line.x=element_line(linetype='dashed')) + theme(legend.position='hidden')

and somehow axis.line overrides axis.line.x.

A workaround would be to stop axis.line overriding with an element_blank(), and blanking axis.line.y if required:

d + theme_minimal() + theme(axis.line = element_line(), axis.line.y=element_blank(), axis.line.x=element_line(linetype='dashed'))

An annoying solution for now. And it appears the same applies to axis.ticks.

I will try to use a different approach for hiding the legend to avoid this problem appearing in my package.

from lemon.

stefanedwards avatar stefanedwards commented on May 28, 2024

And finally, element_* has an argument inherit.blank:

Should this element inherit the existence of an element_blank among its parents? If TRUE the existence of a blank element among its parents will cause this element to be blank as well. If FALSE any blank parent element will be ignored when calculating final element state.

So yeah, that should probably do it.

https://ggplot2.tidyverse.org/reference/element.html

from lemon.

dylanjm avatar dylanjm commented on May 28, 2024

Wow, I didn't think this seemingly small issue would reach so far back into ggplot. Thank you very much for figuring this out. The workaround appears to work well. Thanks again!

from lemon.

stefanedwards avatar stefanedwards commented on May 28, 2024

You are most welcome! Sometimes we stumble over the smallest things. :) And I have looked at the help page for element_blank on countless occasions, but never realised the importance of that one argument.

from lemon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.