ggplot2 - 仅显示 y 轴的上下范围
我的 geom_dotplot 中的 y 轴范围从 0 到 1。点仅在上限和下限范围内。我想将没有点的中间范围 (0.05 - 0.95) 缩小到 0.05 区间,并与 0 - 0.05 之间的下限范围和 0.95-1 之间的上限范围一起显示。 有人可以帮忙吗? 我的代码是:
ggplot(
identical, aes(x=SNV, y=RAF, fill=Mutual_zygosity_of_parents)) +
geom_dotplot(
binaxis = 'y', stackdir = 'center', stackratio = 0, dotsize = 0.3, show.legend = FALSE) +
scale_fill_manual(values=c("cadetblue1")) +
theme(legend.key=element_blank()) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())+
theme(axis.text.y = element_text(face="bold",size=16),
axis.title.y = element_text(face="bold",size=16)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black")) +
expand_limits(x= c(-1,+195))
非常感谢 米洛斯岛
y-axis in my geom_dotplot ranges from 0 to 1. Dots are only in the upper and lower range. I want to shrink the intermediate range with no dots (0.05 - 0.95) into the interval 0.05 and display together with the lower range between 0 - 0.05 and the upper range 0.95-1.
Can anyone help, please?
my code is:
ggplot(
identical, aes(x=SNV, y=RAF, fill=Mutual_zygosity_of_parents)) +
geom_dotplot(
binaxis = 'y', stackdir = 'center', stackratio = 0, dotsize = 0.3, show.legend = FALSE) +
scale_fill_manual(values=c("cadetblue1")) +
theme(legend.key=element_blank()) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())+
theme(axis.text.y = element_text(face="bold",size=16),
axis.title.y = element_text(face="bold",size=16)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black")) +
expand_limits(x= c(-1,+195))
Thanks a lot
Milos
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您的问题不可重现,因为我们没有您的数据,但我们至少可以构建具有相同名称的类似数据结构,以便我们可以使用您的绘图代码来获得类似的结果:
现在这里的问题是ggplot 无法绘制不连续的轴,但通过分面可以相当接近。我们需要做的就是将分面变量设置为 RAF
RAF
RAF
RAF
RAF
RAF
RAF < 0.5
,这会将上点和下点分成各自的组。如果我们还使用scales = "free_y"
,那么 y 轴将“放大”到上下点的范围:Your question is not reproducible since we don't have your data, but we can at least construct a similar data structure with the same names so we can use your plotting code to get a similar result:
Now the problem here is that ggplot cannot do discontinuous axes, but you can come fairly close by faceting. All we need to do is set the faceting variable as
RAF < 0.5
, which will split the upper and lower dots into their own groups. If we also usescales = "free_y"
, then the y axis will "zoom in" to the range of the upper and lower dots: