我的 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))

非常感謝米洛斯
uj5u.com熱心網友回復:
您的問題不可重現,因為我們沒有您的資料,但我們至少可以構建一個具有相同名稱的類似資料結構,以便我們可以使用您的繪圖代碼獲得類似的結果:
set.seed(1)
identical <- data.frame(SNV = factor(sample(1:200, 400, TRUE)),
RAF = c(runif(200, 0, 0.02), runif(200, 0.97, 1)),
Mutual_zygosity_of_parents = "Yes")
p <- 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))
p

現在這里的問題是 ggplot 不能做不連續的軸,但你可以通過刻面來相當接近。我們需要做的就是將 faceting 變數設定為RAF < 0.5,這會將上點和下點分成各自的組。如果我們也使用scales = "free_y",那么 y 軸將“放大”到上下點的范圍:
p facet_grid(RAF < 0.5~., scales = "free_y")
theme(strip.background = element_blank(),
strip.text = element_blank())

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/436091.html
