Skip to content
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

Feature Request: Switch to allow text outside of plotting region #136

Closed
thomasp85 opened this issue May 20, 2019 · 3 comments
Closed

Feature Request: Switch to allow text outside of plotting region #136

thomasp85 opened this issue May 20, 2019 · 3 comments
Labels

Comments

@thomasp85
Copy link

With the possibility of switching of clipping of layers it would be great to be able to loosen the constraint that text must be fully inside the plotting region

@slowkow
Copy link
Owner

slowkow commented May 20, 2019

Do you think the existing xlim and ylim options are sufficient?

I ought to add this example to the vignette.

Here's an example:

library(ggrepel)
library(gridExtra)
set.seed(42)

dat <- subset(mtcars, wt > 2.75 & wt < 3.45)
dat$car <- rownames(dat)

p <- ggplot(dat, aes(wt, mpg, label = car)) +
  geom_point(color = "red")

p1 <- p + geom_text() + labs(title = "geom_text()")

p2 <- p + geom_text_repel() + labs(title = "geom_text_repel()")

p3 <- p + geom_text_repel(xlim = c(-100, 100)) +
  labs(title = "geom_text_repel(xlim = c(-100, 100))")

gridExtra::grid.arrange(p1, p2, p3, ncol = 3)

image


Bug with xlim = c(-Inf, Inf)?

I just now realized that xlim = c(-Inf, Inf) does not work as I would expect, whereas xlim = c(-100, 100) does. I think this is a bug.

# I would expect this to work the same as `xlim = c(-100, 100)`
p + geom_text_repel(xlim = c(-Inf, Inf)) +
  labs(title = "geom_text_repel(xlim = c(-Inf, Inf))")

image

@slowkow slowkow added the bug label May 20, 2019
@thomasp85
Copy link
Author

That is indeed the functionality I'm after. Having it work with Inf would be nice, but for now I think it solves my need. Thanks

@slowkow
Copy link
Owner

slowkow commented May 21, 2019

Here's an example with clipping turned off.

library(ggrepel)
library(gridExtra)
set.seed(42)

dat <- subset(mtcars, wt > 2.75 & wt < 3.45)
dat$car <- rownames(dat)

p <- ggplot(dat, aes(wt, mpg, label = car)) +
  geom_point(color = "red")

p + geom_text_repel(xlim = c(-100, 100), ylim = c(-100, 100)) +
  labs(title = "geom_text_repel()") +
  coord_cartesian(clip = "off") +
  theme(plot.margin = margin(t = 2, r = 3, b = 2.5, l = 2, "cm"))
p

image

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

No branches or pull requests

2 participants