[英]barplot two-sided data sets left and right of y axis
我試圖弄清楚如何制作可以顯示兩個數據集的條形圖。 每個在y軸的一側。 我需要在幾個圖表中顯示許多數據集的空間。 其他選項也可以堆疊或除此以外,但是我想特別了解如何解決此任務,我已經開始嘗試了一些
#creating data
names<-LETTERS[1:9]
data1<-c(8, 6, 3, 2, 0, 1, 1, 3, 1)
data2<-c(0, -1, 0, 0, 0, 0, 0, -2, -1)#negative to show them on the
#left side of yaxis
data1<-matrix(data1,ncol=9,nrow=1,byrow=F)
dimnames(data1)<-list(1,names)
data2<-matrix(data2,ncol=9,nrow=1,byrow=F)
dimnames(data2)<-list(1,names)
par(fig=c(0.5,1,0,1)) # making space for the "left" barplot
barplot(data1,horiz=T,axes=T,las=1)
par(fig=c(0.35,0.62,0,1), new=TRUE)#adjusting the "left" barplot
#because the labels would be negative
# use of axes=F
barplot(data2,axes=F,horiz=T,axisnames=FALSE)
#creating a new axis with desired labels
axis(side=1,at=seq(-8,0,2),labels=c(8,6,4,2,0))
但是我很難理解fig = c(...)背后的概念。我該如何為長度相同的“左” barplot廣告xaxis,即從0:8開始運行
謝謝亞歷克斯
只要您事先知道軸,它就可以工作(在xlim參數中添加)。
我還對您之前的代碼進行了一些編輯,因為我認為您希望輸出看起來像這樣:
par(mfrow=c(1,2))
barplot(data2,axes=F,horiz=T,axisnames=FALSE,
xlim=c(-8,0))
#creating a new axis with desired labels
axis(side=1,at=seq(-8,0,2),labels=c(8,6,4,2,0))
barplot(data1,horiz=T,axes=T,las=1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.