Comments (6)
from lemon.
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.
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.
And finally, element_* has an argument inherit.blank
:
Should this element inherit the existence of an
element_blank
among its parents? IfTRUE
the existence of a blank element among its parents will cause this element to be blank as well. IfFALSE
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.
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.
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)
- scales = 'free_y' doesn't accurately label freed y axes across rows HOT 2
- Legend for pointline is only point HOT 1
- geom_pointline distance = 0 removes the connecting lines entirely. HOT 1
- coord_flex_capped draws axis text to close to ticks HOT 1
- `reposition_legend()` places legend.box behind `facet_rep_grid()` HOT 1
- Change package emoji from tangerine to lemon 🍊➡ 🍋 HOT 2
- lemon print and rounding of values HOT 2
- `mintre` should be `mitre` HOT 1
- `coord_capped_cart()` reverts axis tick length adjustments HOT 1
- Axis line functionality broken in ggplot2 3.3.0 HOT 1
- Invalid line type in geom_pointpath HOT 1
- New grid version causes lemon_plot to fail
- `scales="free"` within `facet_rep_grid` does not make x-axis scales to be free HOT 5
- `facet_rep_grid` layout spacing issues with R 4.0.0 HOT 11
- Issue with next ggplot2 release HOT 4
- Error with coord_capped_cart: Error in `*tmp*`[[i]] : attempt to select less than one element in get1index HOT 1
- Controlling Ticks Repetition. HOT 4
- Issues with next version of ggplot2 HOT 3
- coord_capped_cart() throwing error after recent update HOT 1
- Repeating only x axis? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lemon.