[英]How to get the correct order on the x-axis?
我在 x 軸上的比例順序有問題。
合並和匹配兩個數據幀后,我的輸入文件具有正確的順序。
#data
Eisenberg <- data.frame(scale_hyd = c(0.62, 0.29, -0.9, -0.74, 1.19, 0.48, -0.4,
1.38, -1.5, 1.06, 0.64, -0.78, 0.12, -0.85,
-2.53, -0.18, -0.05, 1.08, 0.81, 0.26),
aa = c('A','C','D','E','F','G','H','I','K','L','M','N',
'P','Q','R','S','T','V','W','Y'))
hydroph <- data.frame(position_aa = c("-10", "-9", "-8", "-7", "-6", "-5", "-4",
"-3", "-2", "-1", "0", "1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11", "12",
"13", "14"),
aa = c("C","V","Q","W","K","N","A","Y","A","L","C","W","L",
"D","C","I","L","S","A","L","V","H","S","E","E"))
#combining data
res <- merge(Eisenberg, hydroph)
res1 <- res[match(hydroph$position_aa, res$position_aa), ]
view(res1)
#visualisation of data
ggplot(res1, aes(x=position_aa, y=scale_hyd)) +
geom_boxplot() +
labs(x="Amino acid position", y="Eisenberg scale", title="Hydrophobicity") +
theme_bw() +
theme(legend.position="none") +
geom_dotplot(binaxis="y", stackdir="center", fill="black")
如果您能幫我在 x 軸上放置正確的 position_aa 順序,我將不勝感激:
-10 -9 -8 ... 14
而不是:-1 -10 -2 ...
按照建議,我添加了res1$position_aa <- as.numeric(res1$position_aa)
奇怪的是,無論我們做什么,這個包似乎都以某種方式將價值觀強制恢復為角色。
您可以嘗試使用基礎 R 圖。 首先,我們需要一個具有數字有序級別的"factor"
變量。
res$position_aa <- factor(res$position_aa, levels=-10:14)
然后我們使用plot
,它使用graphics:::plot.factor
方法,通過我們給予充分的水平排序。 之后,我們添加points
並使用abline
制作網格。 就是這樣。
with(res, plot(position_aa, scale_hyd, main="Hydrophobicity",
xlab="Amino acid position",
ylab="Eisenberg scale"))
with(res, points(position_aa, scale_hyd, pch=16, cex=1.5))
.col <- rgb(0, 0, 0, .25) ## alpha .25 for transparency
abline(h=axTicks(2), lty=3, col=.col)
abline(v=seq(-10:14), lty=3, col=.col)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.