admin 管理员组文章数量: 1086019
I want to make a plot composed out of two plots with both having the same broken y axis and forced into one column. However, ggplot2
always mixes the two plots into this scheme:
[plot1 higher y-axis]
[plot2 higher y-axis]
[plot1 lower y-axis]
[plot2 lower y-axis]
But I need:
[plot1 higher y-axis]
[plot1 lower y-axis]
[plot2 higher y-axis]
[plot2 lower y-axis]
I guess the solution is pretty easy, but I just can't seem to find it. Here's an MRE:
library(ggplot2)
library(ggbreak)
library(tibble)
xs <- c(1, -1, 1, -1)
ys <- c(5, 100, 10, 200)
group <- c("one", "one", "two", "two")
data <- tibble(xs = xs,
xy = ys,
group = group)
(
plot <-
ggplot(data, aes(xs, ys)) +
geom_point() +
facet_wrap(~group,
ncol = 1) +
scale_y_break(c(20, 90))
)
I want to make a plot composed out of two plots with both having the same broken y axis and forced into one column. However, ggplot2
always mixes the two plots into this scheme:
[plot1 higher y-axis]
[plot2 higher y-axis]
[plot1 lower y-axis]
[plot2 lower y-axis]
But I need:
[plot1 higher y-axis]
[plot1 lower y-axis]
[plot2 higher y-axis]
[plot2 lower y-axis]
I guess the solution is pretty easy, but I just can't seem to find it. Here's an MRE:
library(ggplot2)
library(ggbreak)
library(tibble)
xs <- c(1, -1, 1, -1)
ys <- c(5, 100, 10, 200)
group <- c("one", "one", "two", "two")
data <- tibble(xs = xs,
xy = ys,
group = group)
(
plot <-
ggplot(data, aes(xs, ys)) +
geom_point() +
facet_wrap(~group,
ncol = 1) +
scale_y_break(c(20, 90))
)
Share
Improve this question
edited Mar 28 at 9:03
xilliam
2,2792 gold badges17 silver badges29 bronze badges
asked Mar 27 at 11:23
gernophilgernophil
4955 silver badges18 bronze badges
1 Answer
Reset to default 0I would say to make sub plots and then arrange them together with patchwork library.
From what I understood, this should be what you're looking for:
library(patchwork)
plot1 <-
ggplot(data=data[data$group=="one",], aes(x=xs, y=xy)) +
geom_point() +
scale_y_break(c(20, 90))
plot2 <-
ggplot(data=data[data$group=="two",], aes(x=xs, y=xy)) +
geom_point() +
scale_y_break(c(20, 90))
design <-"12"
plot1 + plot2 + plot_layout(design = design)
本文标签: rkeep plots together with facetwrap() and scaleybreak()Stack Overflow
版权声明:本文标题:r - keep plots together with facet_wrap() and scale_y_break() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744093549a2532481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论