2016-06-01 14 views
0

barchartからy軸ティックを削除しようとしています。barchartではなく、barplotでyaxis ticksを削除します。

googleはbarchartをbarplotに直ちに修正して、役に立たない。

yaxt =「N」

誰もがどのように削除するy軸はRで棒グラフでダニのアイデアを持っている...棒グラフで作業していませんか?これは私がそれを望むようにグループに私のためにデータを働く私は見つけることができる唯一の方法があるので、私は棒グラフが必要

...

MWEはここにある:

library(lattice) 

molnames<-c("A","B","D","G","C","F") 
contactcounts<-c(1,2,3, 6,12,18,4,8,16,10,20,30,2,4,8,3,6,9) 

Acolumn1=factor(rep(molnames, each=3), levels=molnames) 
Acolumn2=rep(c("test1","test2","test3"), 6) 
Acolumn3=contactcounts 
colour<-c("orange", "blue","magenta") 
tiff(file="./testingABC.tiff", res=1000, width = 8, height = 8,units='in') 
trellis.par.set("grid.pars"=list(fontfamily="serif")) 
barchart(Acolumn3 ~ Acolumn1,ylab="y axis", yaxt="n", groups=Acolumn2, auto.key = list(columns = 3), par.settings=list(superpose.polygon=list(col=colour))) 

答えて

1

してくださいラティスパッケージからの関数を使用していて、基本パッケージからではなく、異なるパラメータを使用していることに注意してください。
目的を達成するには、scalesパラメータを設定する必要があります(?barchartのドキュメントを参照)。 slighlty異なる結果を与える2つのオプションがあります。

# option 1: we're saying that y ticks must be set at coordinate = NULL 
barchart(Acolumn3 ~ Acolumn1,ylab="y axis", groups=Acolumn2, auto.key = list(columns = 3), 
     scales=list(y=list(at=NULL)), 
     par.settings=list(superpose.polygon=list(col=colour))) 

enter image description here

# option 2: we're saying not to draw y axis 
barchart(Acolumn3 ~ Acolumn1,ylab="y axis", groups=Acolumn2, auto.key = list(columns = 3), 
     scales=list(y=list(draw=FALSE)), 
     par.settings=list(superpose.polygon=list(col=colour))) 

enter image description here


はここでベースRを使用してbarplotを行う方法の例です:

# Acolumn1,Acolumn2,Acolumn3 have been created in your example 
DF <- data.frame(Acolumn1,Acolumn2,Acolumn3) 

###### build matrix to be passed to barplot using R base 
reshaped <- reshape(DF, idvar="Acolumn1",timevar="Acolumn2", direction = "wide",sep='_') 
names(reshaped) <- gsub('Acolumn3_','',names(reshaped)) 
reshapedMx <- as.matrix(reshaped[,-1]) 
rownames(reshapedMx) <- reshaped[,1] 
reshapedMx <- t(reshapedMx) 

###### build matrix to be passed to barplot using reshape2 package (less code) 
# library(reshape2) 
# reshapedMx <- acast(DF, Acolumn1 ~ Acolumn2, value.var='Acolumn3') 
# reshapedMx <- t(reshapedMx) 

colors <- rainbow(nrow(reshapedMx)) 
barplot(reshapedMx,beside = TRUE,col=colors,ylim=c(0,max(reshapedMx)*1.2), yaxt='n') 
legend('top',fill=colors,legend=rownames(reshapedMx), horiz=TRUE) 
# call box() if you want to add a box around the plot 

enter image description here

+0

ありがとう、それはうまく動作します。セカンダリy軸のティックを隠す方法はありますか? – gugy

+0

ここでは二次y軸は表示されません。例を挙げてください...ベースプロットの代わりに格子を使用する理由は何ですか? – digEmAll

+0

これは私が実際に望んでいたことを見つけ出し、働いた(そして私が理解した...) MWEをプロットすると、左にセカンドY軸が得られます。 Ubuntu 14.04とR 3.2.2を使用しています – gugy

関連する問題