2012-09-06 11 views
17

次のプロットを作成すると、プロット領域と軸(つまり青色のボックスとx軸の間の空白)が不要になります。プロットとプロットエリアのフラッシュは?軸感謝。プロット領域の周りの間隔をr内に取り除く

xleft<-c(1,2,2.5) 
xright<-c(2,2.5,2.75) 
ybottom<-c(1,2,2.5) 
ytop<-c(2,2.5,2.75) 

par(mar = c(15,15,2.75,2.75) + 0.1) 
plot(c(1,2.75),c(1,2.75),type="n",main="title",xlab="site.x",ylab="ylab") 
rect(xleft,ybottom,xright,ytop,col=c("blue","red","green")) 

#Label position along axes 
x.label.position<-(xleft+xright)/2 
y.label.position<-(ybottom+ytop)/2 

#Labels 
x.label<-c("Long species Name1","Long species Name2","Long species Name3") 
y.label<-c("Long species Name4","Long species Name5","Long species Name5") 

text(par()$usr[1]-0.5,y.label.position,y.label,xpd=TRUE,adj=1) 
text(y=par()$usr[3]-0.5,x=x.label.position,x.label,xpd=TRUE,adj=1,srt=90) 

par(xpd=TRUE) 
legend(-0.1,0,legend=c("Species A","Species B","Species C"),fill=c("blue", "red", "green")) 

enter image description here

UPDATE は私の実際のデータでplannapusからの提案を試みたが、のみ動作するようにy軸を得ることができ、この中であり、いくつかの他のですプロット領域の両側にスペースを追加するコードチャンク?

quartz("colour.plot") 
par(mar=c(15,15,4,2)+0.1)#sets margins of plotting area 

#create the data plot 
    plot(c(0,100), c(0,100), type = "n", main = paste(x,"vs",y," -",depth),xlab=paste("Species composition in remainder ",x),ylab=paste("Species composition in remainder ",y),asp=1,xaxs="i",yaxs="i") 

#Add the rectangles 
rect(mdf$xleft,mdf$ybottom,mdf$xright,mdf$ytop,col=mdf$colour) 

すべての軸は、次にあなたが欲しいposに新しい軸を追加することができます削除されている

enter image description here

+0

は、「プロットエリアの両側にスペースを追加してこのコードの塊であり、いくつかの他のですか?」はい: 'asp = 1'。これにより、x軸とy軸が等しくなるように強制されます。おそらくプロット領域のサイズと矛盾します。 – plannapus

+0

'plot'を呼び出す前に' par(pty = "s") 'を追加すると、プロット領域が画像上と同じように四角形(したがって' 's" ')になり、 "不具合"。 – plannapus

+0

私はあなたが@plannapusの答えに行くべきだと思うか、プロットしたい領域にマッチするように 'xlim'、' ylim'を設定してください。 @アランのソリューションは正しい外観を示していますが、あなたがここでやりたいことは概念的に正しいとは言えません。それは言うだけで "症状を治す"。 – Backlin

答えて

24

plotには、xaxs(およびy軸の場合はyaxs)を処理する引数があります。 デフォルトでは、xaxs="r"に設定され、軸値の4%が各側に残されます。これを0に設定するには:xaxs="i"。詳細については、?parxaxsセクションを参照してください。

plot(c(1,2.75),c(1,2.75),type="n",main="title",xlab="site.x",ylab="ylab", xaxs="i", yaxs="i") 
rect(xleft,ybottom,xright,ytop,col=c("blue","red","green")) 

enter image description here

+0

@planapus解決策を使用したいと思いますが、解決策のx軸の両側にスペースを追加するasp = 1を使用しているため問題があります(問題の更新例を参照)。とにかくこの問題を避けるためにはありますか? – Elizabeth

+0

@Elizabeth上記のコメントで提案した 'par(pty =" s ")'を試しましたか? (理想的には、解決策はプロット領域のサイズを正確に定義することですが、それは苦労です) – plannapus

+0

私はその行に誤りがあったことに気づきました。修正され、今は動作します。ありがとう:) – Elizabeth

4
plot(c(1,2.75),c(1,2.75),type="n",main="title",xlab="site.x",ylab="ylab",axes=F) # ann 
axis(1,pos=1) 
axis(2,pos=1) 

を生成します。

+0

正しく動作しますが、この解決策は軸を移動させますが、プロット領域は変更しないことに注意してください。 – plannapus

関連する問題