我有兩個散點圖,基於不同但相關的數據,使用gplot2中的qplot()創建。 (學習ggplot
不是一個優先事項,因爲qplot
已經足以滿足我的需求)。我想要做的是疊加/疊加這兩個圖表,使每個x,y數據都繪製在同一個繪圖空間中。複雜的是,我希望每個情節都保留其格式/美學。覆蓋ggplot2中兩個不同格式的qplots
有問題的數據是來自對應分析的行和列分數 - corresp()
從MASS
- 因此兩個數據集之間的數據行數(即樣本或分類羣)不同。我可以輕鬆地將兩個樂譜組合在一起。要麼通過梳理兩個數據集,要麼更簡單,只需使用biplot()
函數。然而,我一直在使用qplot來獲取完全按照我需要的圖形;與樣本繪製彩色編碼符號和類羣如標籤:
PlotSample <- qplot(DataCorresp$rscore[,1], DataCorresp$rscore[,2],
colour=factor(DataAll$ColourCode)) +
scale_colour_manual(values = c("black","darkgoldenrod2",
"deepskyblue2","deeppink2"))
和
PlotTaxa <- qplot(DataCorresp$cscore[,1], DataCorresp$cscore[,2],
label=colnames(DataCorresp), size=10, geom=「text」)
任何人都可以提出一個方法,通過該要麼
- 兩個地塊(
PlotSample
和PlotTaxa
)可疊加在彼此之上, - 兩個數據集(
DataCorresp$rscore
和DataCorresp$cscore
)可以一起繪製,但是以其不同的方式格式化,或者另外的功能(例如,biplot()
)可以用來實現我的目標。> require(MASS) > require(ggplot2) > alldata<-read.csv("Fake data.csv",header=T,row.name=1) > selectdata<-alldata[,2:10] > alldata Period Species.1 Species.2 Species.3 Species.4 Species.5 Species.6 Sample-1 Early 50 87 97 12 60 49 Sample-2 Early 41 90 36 52 36 27 Sample-3 Early 87 56 82 45 56 13 Sample-4 Early 37 47 78 29 53 34 Sample-5 Early 58 70 34 35 8 21 Sample-6 Early 94 82 48 16 27 26 Sample-7 Early 91 69 50 57 24 13 Sample-8 Early 63 38 86 20 28 11 Sample-9 Middle 4 19 55 99 86 38 Sample-10 Middle 29 25 10 93 37 54 Sample-11 Middle 48 12 59 73 39 92 Sample-12 Middle 31 6 34 81 39 54 Sample-13 Middle 29 40 26 52 34 84 Sample-14 Middle 1 46 15 97 67 41 Sample-15 Late 43 47 30 18 60 23 Sample-16 Late 45 10 49 2 2 45 Sample-17 Late 14 8 51 36 58 51 Sample-18 Late 41 51 32 47 23 43 Sample-19 Late 43 17 6 54 4 12 Sample-20 Late 20 25 1 29 35 2 Species.7 Species.8 Species.9 Sample-1 41 39 57 Sample-2 59 4 45 Sample-3 10 56 5 Sample-4 59 30 39 Sample-5 9 29 57 Sample-6 29 24 35 Sample-7 22 4 42 Sample-8 31 19 40 Sample-9 17 7 57 Sample-10 6 9 29 Sample-11 34 20 0 Sample-12 56 41 59 Sample-13 6 31 13 Sample-14 25 12 28 Sample-15 60 75 84 Sample-16 32 69 34 Sample-17 48 53 56 Sample-18 80 86 46 Sample-19 50 70 82 Sample-20 57 84 70 > biplot(selectca,cex=c(0.6,0.6)) > selectca<-corresp(selectdata,nf=5) > PlotSample <- qplot(selectca$rscore[,1], selectca$rscore[,2], colour=factor(alldata$Period)) > PlotTaxa<-qplot(selectca$cscore[,1], selectca$cscore[,2], label=colnames(selectdata), size=10, geom="text")
的雙標圖將產生該曲線:使用非常簡化的和虛構的數據集的工作流的
實施例/ R/10wk1a8/5
的PlotSample顯示爲這樣:/ R/i29cba/5
的PlotTaxa出現這樣:/ R/245bl9d/5
EDIT所以沒有足夠的代表發佈圖片和不明的鏈接(儘管https://meta.stackexchange.com/questions/60563/how-to-upload-images-on-stack-overflow)。因此,如果您將tinypic的網址添加到上面這些代碼的開頭,那麼您會到達那裏。
本質上我想創建雙色圖,但樣品顏色編碼,因爲它們在PlotSample中。
請[提供數據](http://stackoverflow.com/a/5963610/1412059)進行測試。 – Roland
是[this](http://stackoverflow.com/q/6620375/707145)有幫助嗎? – MYaseen208