在為此作業了 4 小時后,我幾乎對這個錯誤感到絕望,谷歌搜索并查看了過去的帖子。
這是我的資料結構:
str(tcga_exp)
'data.frame': 11775 obs. of 5 variables:
$ cohort: chr "BRCA-Basal.Tumor" "BRCA-LumA.Tumor" "BRCA-LumB.Tumor" "BRCA-LumA.Tumor" ...
$ exp : num 6.35 5.54 6.56 5.05 5.98 ...
$ group : chr "Tumor" "Tumor" "Tumor" "Tumor" ...
$ comp : chr "no" "no" "no" "no" ...
但它不會像下面的代碼那樣作業:
bp = ggplot(tcga_exp, aes(x=cohort, y=exp,color=group)) geom_rect(data = box_df,aes(xmin=normal,xmax=tumor,ymin=-Inf, ymax=Inf),color="grey",alpha= 0.2)
geom_boxplot() geom_jitter(shape=16,alpha = 0.2,position=position_jitter(0.2),aes(color = group))
ylab(label = "log2(TPM 1)") scale_color_manual(values = c("Tumor" = "#FD0606", "Normal" = "#1F25F9","Metastatic" = "#A432EB"))
theme_bw() theme(axis.text.x = element_text(angle = 90,hjust=0.95,vjust=0.2),legend.position = "none",axis.title.x = element_blank())
# add signif
bp = bp geom_signif(comparisons = compare,map_signif_level = T,tip_length = 0, color = "black",textsize = 3,vjust = 0.5)
bp
Error in FUN(X[[i]], ...) : object 'cohort' not found
但我認為“佇列”在我的資料列中。
但它在沒有 geom_rect 部分的情況下作業。
bp = ggplot(tcga_exp, aes(x = cohort, y = exp,color = group)) geom_boxplot() geom_jitter(shape=16,alpha = 0.2,position=position_jitter(0.2),aes(color = group))
ylab(label = "log2(TPM 1)") scale_color_manual(values = c("Tumor" = "#FD0606", "Normal" = "#1F25F9","Metastatic" = "#A432EB"))
theme_bw() theme(axis.text.x = element_text(angle = 90,hjust=0.95,vjust=0.2),legend.position = "none",axis.title.x = element_blank())
# add signif
bp = bp geom_signif(comparisons = compare,map_signif_level = T,tip_length = 0, color = "black",textsize = 3,vjust = 0.5)
bp
補充:
str(box_df)
$ normal: chr "BLCA.Normal" "BRCA-Normal.Normal" "CHOL.Normal" "COAD.Normal" ...
$ tumor : chr "BLCA.Tumor" "BRCA.Tumor.Tumor" "CHOL.Tumor" "COAD.Tumor" ...
我正在嘗試制作類似這樣的數字 在此處輸入影像描述
由于資料很長,我將資料上傳到谷歌驅動器以進行重現。 https://drive.google.com/file/d/1logQXXkmVpV0jy4i-MrMYRQ8UiFEOFmQ/view?usp=sharing
在繼續研究這個之后,我意識到如果你不把 aes() 放在 ggplot() 中而是放在后面:geom_boxplot 和 geom_jitter,你可以繪制 geom_rect,但這仍然不能解決我的問題,因為那樣我就可以了t 做 geom_signif 比較。
bp = ggplot(tcga_exp) geom_rect(data = box_df,aes(xmin = normal,xmax=tumor,ymin=-Inf, ymax=Inf),color="grey",alpha= 0.2) geom_boxplot(aes(x = cohort, y = exp,color = group)) geom_jitter(shape=16,alpha = 0.2,position=position_jitter(0.2),aes(x = cohort, y = exp,color = group))
ylab(label = "log2(TPM 1)") scale_color_manual(values = c("Tumor" = "#FD0606", "Normal" = "#1F25F9","Metastatic" = "#A432EB"))
theme_bw() theme(axis.text.x = element_text(angle = 90,hjust=0.95,vjust=0.2),legend.position = "none",axis.title.x = element_blank())
# add signif
bp = bp geom_signif(comparisons = compare,map_signif_level = T,tip_length = 0, color = "black",textsize = 3,vjust = 0.5)
bp
Error in f(...) : Can only handle data with groups that are plotted on the x-axis
謝謝!!!
uj5u.com熱心網友回復:
映射您的主要美學ggplot()。然后inherit.aes=FALSE在要使用不同資料定義的幾何圖形中使用。
dat <- readRDS("sample.RDS")
box_df <- data.frame(normal = c("BLCA.Normal", "BRCA-Normal.Normal", "CHOL.Normal", "COAD.Normal"),
tumor = c("BLCA.Tumor", "BRCA.Tumor.Tumor", "CHOL.Tumor", "COAD.Tumor"))
ggplot(dat=dat, aes(x=cohort, y=exp, color=group))
geom_rect(data=box_df, aes(xmin=normal, xmax=tumor, ymin=-Inf, ymax=Inf),
color = "grey", alpha=0.2, inherit.aes=FALSE)
geom_boxplot()
geom_jitter(shape=16, alpha=0.2, position=position_jitter(0.2))
geom_signif(comparisons=compare, map_signif_level=TRUE, tip_length=0, color="black",textsize=3, vjust=0.5, inherit.aes=FALSE)
scale_color_manual(values = c("Tumor" = "#FD0606", "Normal" = "#1F25F9","Metastatic" = "#A432EB"))
theme_bw()
theme(axis.text.x = element_text(angle=90, hjust=0.95, vjust=0.2),
legend.position = "none", axis.title.x = element_blank())
沒有你的所有資料,我無法測驗它的完整性。如果這不起作用或您需要更多幫助,請告訴我!
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/384686.html
