Skip to content

facet plots: strip.text.y & strip.position = 'left' not accepting angle argument #3888

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

Closed
sebdunnett opened this issue Mar 11, 2020 · 10 comments · Fixed by #3896
Closed

facet plots: strip.text.y & strip.position = 'left' not accepting angle argument #3888

sebdunnett opened this issue Mar 11, 2020 · 10 comments · Fixed by #3896

Comments

@sebdunnett
Copy link

Hi, thanks for all your work on ggplot2; first issue report for me. I recently updated to ggplot2 3.3.0 and my code to produce facet maps with facet strips on the left no longer seems able to produce text the right way up. Reprex below

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~cyl, strip.position = 'right') +
  theme(strip.text.y = element_text(angle=45))

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~cyl, strip.position = 'left') +
  theme(strip.text.y = element_text(angle=45))
@batpigandme
Copy link
Contributor

Just adding a reprex with the rendered plots

library(tidyverse)
ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~cyl, strip.position = 'right') +
  theme(strip.text.y = element_text(angle=45))

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~cyl, strip.position = 'left') +
  theme(strip.text.y = element_text(angle=45))

Created on 2020-03-11 by the reprex package (v0.3.0.9001)

@clauswilke
Copy link
Member

This works.

library(ggplot2)

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~cyl, strip.position = 'left') +
  theme(strip.text.y.left = element_text(angle=45))

Created on 2020-03-11 by the reprex package (v0.3.0)

@batpigandme
Copy link
Contributor

I suspected as much, but it wasn't in autosuggest, so I thought it didn't exist 🙃

@clauswilke
Copy link
Member

Not sure whether the other code should work also. I'll leave that for somebody else to decide.

@thomasp85
Copy link
Member

I think the main “issue” is that the vertical strips have different rotation for left and right by default and as such you have to overwrite it at that level for it to go into effect.

@sebdunnett
Copy link
Author

Thank you @clauswilke , I didn't know about strip.text.y.left.

@rbreejen
Copy link

rbreejen commented Mar 15, 2020

I am seeing the same issue with facet_grid. The accepted answer provided in this Stackoverflow question does not work anymore.

Code:

df <- group_by(mpg, manufacturer) %>%
  summarise(cty = mean(cty), hwy = mean(hwy)) %>%
  ungroup()

df <- melt(df, id.vars = "manufacturer")

ggplot() +
  geom_bar(data =df, aes(x = variable, y = value), stat = "identity") +
  facet_grid(manufacturer ~ ., switch = "y")+
 theme(strip.text.y = element_text(angle = 180))

@clauswilke
Copy link
Member

Yes, this change was introduced deliberately in #3683. I think we didn't mention this in the changelog and we should have. I have edited the SO answer so it's correct now.

@rbreejen Note that the previous working code had an obvious flaw: You had to specify angle = 180 to get an angle of 0, because the code internally was manipulating the rotation angle when switching the location of the strips. That was confusing, and also inconsistent with how axes work.

@thomasp85 Can we retroactively add a news item to the 3.3.0 release? Or should we add it to 3.3.1 but point out the change happened already in 3.3.0? The second seems cleaner to me.

@thomasp85
Copy link
Member

Let’s add it to 3.3.1

@pabgamu
Copy link

pabgamu commented Sep 8, 2021

Thanks for this fix, I have been reviewing both this and #3896 tickets and I think it should make sense to add strip.text.y.left/right and strip.text.x.top/bottom to theme inputs for consistency sake, similar to axis.title.x.top, etc., I think this will be very helpful for any user, specially new ones, as I think these inputs are only mentioned in news file, please let me know if I am wrong about this.
I can open new ticket or submit pull request if more convenient, just let me know, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants