2016-06-01 4 views
0

barchart에서 y 축 틱을 제거하려고합니다.barchart가 아닌 barplot은 yaxis 틱을 제거합니다.

google은 즉시 바둑판을 바 plot으로 수정하며 전혀 도움이되지 않습니다.

yaxt = "n"은

사람은 어떻게 제거하기 위해 y 축이 R에 barcharts 틱 아이디어가 ... 막대 그래프 작동하지 않습니다? 이것이 내가 원하는 방식으로 그룹에 나를 위해 내 데이터를 작동 내가 찾을 수있는 유일한 방법이기 때문에 내가 막대 그래프가 필요

...

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 설명서 참조). 어떻게 기본 R 사용 barplot을 수행하는

# 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


여기 예입니다 :

# 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 
을 slighlty 다른 결과를 제공하는 두 가지 옵션이 있습니다

enter image description here

+0

감사합니다. 2 차 y 축에 대한 틱을 어떻게 숨길 수 있습니까? – gugy

+0

여기에 seconday y 축이 보이지 않습니다. 예제를 제공해주세요 ... BTW 기본 플롯 대신 격자를 사용하는 이유는 무엇입니까? – digEmAll

+0

이것은 내가 실제로 원했던 일을 찾아 낼 수있는 유일한 방법이었습니다. (이해할 수있는 것은 ...) MWE를 그릴 때 왼쪽에 2 차 y 축을 얻었습니다 ... 우분투 14.04 및 R 3.2.2를 사용하고 있습니다. – gugy