-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Tag positioning not working? #2882
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
Comments
Using library(dplyr)
library(ggplot2)
mpg <- mpg %>%
filter(cyl == 4 | cyl == 8)
p <- ggplot(mpg, aes(displ, cty)) +
geom_point() +
facet_grid(cols = vars(cyl)) +
labs(tag = 'A)') +
theme_minimal() +
theme(plot.caption = element_text(size = 14)) +
theme(plot.margin = margin(t = 20, r = 20, b = 20, l = 20))
p + theme(plot.tag.position = "topright") p + theme(plot.tag.position = "bottomleft") Created on 2018-09-05 by the reprex package (v0.2.0.9000). |
@batpigandme thank you for checking! What I meant was that can we move the tag around after we specify its position? For example: moving the tag away or up/down the right border of the plot when use library(dplyr)
library(ggplot2)
mpg <- mpg %>%
filter(cyl == 4 | cyl == 8)
p <- ggplot(mpg, aes(displ, cty)) +
geom_point() +
facet_grid(cols = vars(cyl)) +
labs(tag = 'A)') +
theme_bw() +
theme(plot.caption = element_text(size = 14)) +
theme(plot.margin = margin(t = 20, r = 20, b = 20, l = 20)) p3 <- p +
labs(caption = "right") +
theme(plot.tag.position = 'right')
p3 |
Apparently not. I suspect this is a bug that can be fixed. In the mean time, you can specify the tag position via a two-dimensional numerical vector, just like the legend position, and that should allow you to move the tag anywhere you want. |
Ah! OK. I see what you mean now. Yeah, this was something that came up in the PR thread (@clauswilke just beat me to it, as I was finding his old comment): |
@clauswilke : could you post a working example? I couldn't get it to work for library(dplyr)
library(ggplot2)
mpg <- mpg %>%
filter(cyl == 4 | cyl == 8)
p <- ggplot(mpg, aes(displ, cty)) +
geom_point() +
facet_grid(cols = vars(cyl)) +
labs(tag = 'A)') +
theme_bw() +
theme(plot.caption = element_text(size = 14)) +
theme(plot.margin = margin(t = 20, r = 20, b = 20, l = 20))
p3 <- p +
labs(caption = "right")
p3 + theme(plot.tag.position = c(0.5, 0.5)) p3 + theme(plot.tag.position = c(1.1, 0.75)) p3 + theme(plot.tag.position = c(8, 25)) |
The numbers have to be between 0 and 1, just like for |
@clauswilke : wouldn't it place the tag inside the facet with the value being from 0 to 1? |
I'm worried that the main point of this issue is getting lost, so I'm showing it here in a minimal reprex: library(ggplot2)
p <- ggplot() + labs(tag = "A") +
theme(plot.tag.position = "right")
# vjust setting cannot be used to move the
# label vertically by a meaningful amount
p + theme(plot.tag = element_text(vjust = 0)) p + theme(plot.tag = element_text(vjust = 1)) Created on 2018-09-06 by the reprex package (v0.2.0). Similar problems exist for tags at the top or bottom of a plot and the |
Is there any update on this issue? Thank you! |
you can use the margin argument in p3 <- p +
labs(caption = "right") +
theme(
plot.tag.position = 'right',
plot.tag = element_text(margin = margin(l = 12))
) |
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/ |
Hello,
I used
hjust
andvjust
forplot.tag
but it didn't seem to work. Is it an intended behavior? How can I move the tag away from the plot region especially when placing it on theright
?Thank you!
The text was updated successfully, but these errors were encountered: