我現在用的是試圖繪制ggplot2 geom_point呼叫R。但是,當我繪制所需的圖形時,作為單詞(而非數字)的 X 標簽并未全部顯示在 X 軸上。
首先,這里有一些可重復的資料:
Bac <- data.frame(logFC = seq(-1, 3.5, 0.19),
ASV_Fam = c("ASV_31; Bdellovibrionaceae", "ASV_152; Reyranellaceae", "ASV_102; Hymenobacteraceae", "ASV_124; Nitrospiraceae", "ASV_141; NA",
"ASV_180; Microscillaceae", "ASV_259; Microscillaceae", "ASV_272; Chitinophagaceae", "ASV_79; Chthoniobacteraceae",
"ASV_266; Chthoniobacteraceae", "ASV_106; Nitrosomonadaceae", "ASV_121; Nitrospiraceae", "ASV_184; Methylophilaceae", "ASV_115; Chthoniobacteraceae",
"ASV_123; Nitrosomonadaceae", "ASV_143; Haliangiaceae", "ASV_139; NA", "ASV_159; Micrococcaceae", "ASV_185; Xanthobacteraceae", "ASV_227; Chitinophagaceae",
"ASV_233; NA", "ASV_239; Chitinophagaceae", "ASV_255; NA", "ASV_204; Longimicrobiaceae"),
Phylum = c("Bdellovibrionota", "Proteobacteria", "Bacteroidota", "Nitrospirota",
"Proteobacteria", "Bacteroidota", "Bacteroidota", "Bacteroidota",
"Verrucomicrobiota", "Verrucomicrobiota", "Proteobacteria", "Nitrospirota",
"Proteobacteria", "Verrucomicrobiota", "Proteobacteria", "Myxococcota",
"Proteobacteria", "Actinobacteriota", "Proteobacteria", "Bacteroidota",
"Proteobacteria", "Bacteroidota", "Cyanobacteria","Gemmatimonadota"))
Bac$Family <- gsub("^[^.]*;", "", Bac$ASV_Fam)
我發現最接近我的錯誤的是這篇文章:
As you can see, it only plotted 14 of my 24 labels I have passed for the X-axis. All of my points are there, but some vertical lines show more than 1 point and only 1 label is associated with that vertical line. See for example X-axis labels: ASV_152; Reyranellaceae, ASV_102; Hymenobacteraceae, ASV_266; Chthoniobacteraceae, etc.
I am not sure why these are not given separate X-axis labels and are instead being graphed on the same vertical line, thus reducing the total labels plotted on the X-axis.
Other work arounds I have tried: widening the pdf via the pdf() command, widening the graph by passing coord_fixed(ratio = 0.25), but none of these options work.
此外,傳遞以下代碼scale_y_discrete(breaks = seq(-1, 4, 0.5))使我不能在 Y 軸上顯示這么多數字是行不通的。我認為這是因為 y 軸已被設定為一個因子,所以我嘗試將其保留為數字,但這也不起作用。
任何有關正在發生的事情的線索都會非常有幫助!
作為參考,這是我的會話的輸出 sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6
uj5u.com熱心網友回復:
當您檢查 時dim(table(Bac$Family)), 中存在14唯一值Family,并且當您通過 設定繪圖的 x 軸時x = Family,僅存在 14 個值。
我不確定你的目的,但如果你想要ASV_Famx 軸上的所有 24 個標簽(),每個標簽一個點,而不是x = Family,試試x = ASV_Fam
如果這個情節不是你想要的,請告訴我。
ggplot(Bac, aes(x = ASV_Fam, y = logFC, color = Phylum)) geom_point()
theme(axis.text.x = element_text(colour = "black", size = 9, angle = -90))

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/326983.html
上一篇:自動停止圖例被圖裁剪(R)
