-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Remove extra space created by coord_trans
#3338
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
you need to manually set you r discrete x expansions library(ggplot2)
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
library(ggbeeswarm)
library(patchwork)
## top panel
p1 <- ggplot(mpg, aes(class,cty) )+
geom_quasirandom()+
coord_trans(y="log2")+
scale_x_discrete(expand=c(0,0.6))
## bottom panel
p2 <- ggplot(mpg, aes(class,fill=drv))+
geom_bar(position = "fill")+
scale_x_discrete(expand=c(0,0.6))
p1 + p2 + plot_layout(ncol = 1) Created on 2019-05-22 by the reprex package (v0.3.0) |
Thanks for the reply. But it doesn't fix the problem. If you see in |
It looks like library(ggplot2)
library(patchwork)
p <- ggplot(mpg, aes(class, cty))+
geom_boxplot()
wrap_plots(
p,
p + scale_y_continuous(trans = "log2", breaks = seq(10, 35, by = 5)),
ncol = 1
) If you really need library(ggplot2)
library(patchwork)
p <- ggplot(mpg, aes(class, cty))+
geom_boxplot()
wrap_plots(
p + coord_cartesian(xlim = c(0.4, 7.6), expand = FALSE),
p + coord_trans(y = "log2", limx = c(0.4, 7.6)),
ncol = 1
) Created on 2019-05-22 by the reprex package (v0.2.1) |
Hi @paleolimbot thanks a lot for the suggestion. The second approach seems to be working as expected. When I used the first approach, after Thanks a lot for the help. |
I don't think it's the library(ggplot2)
library(patchwork)
p <- ggplot(mpg, aes(class, cty)) +
geom_boxplot(aes(class, cty)) +
geom_rect(
aes(xmin = xmin, xmax = xmax),
data = data.frame(xmin = c(0.5, 3.5), xmax = c(1.5, 4.5)),
ymax = Inf,
ymin = -Inf,
alpha = 0.1,
inherit.aes = FALSE
)
wrap_plots(
p,
p + scale_y_continuous(trans = "log2", breaks = seq(10, 35, by = 5)),
ncol = 1
) Created on 2019-05-22 by the reprex package (v0.2.1) |
If I plot |
I would encourage you to reach out at https://community.rstudio.com/ for questions like these! Here we are concerned with unexpected behaviour or features that you feel should be added. In this case, we're concerned with the irregular behaviour of scale expansion in |
Sure thing. Thanks for pointing it out. |
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/ |
I'm trying to produce a two panel figure for my data. At one point I had to use
coord_trans
in my code which created an extra space between y-axis and first beeswarm dots.Here is the figure
I would like to remove the space between y-axis and first set of dots so that gray-white shading align in 2 panels. If I don't use
coord_trans
, shadings are aligned perfectly. Although,coord_trans
documentation says that it will change visual appearance of geoms, I'm hoping there might be a solution to produce a figure I'm thinking of.Following is the sample data and to reproduce the figure
data: Link to data
Thanks a lot for the great package and support.
The text was updated successfully, but these errors were encountered: