2014-09-03 5 views
0

enter image description here 사진에서 볼 수있는 것처럼 막대 그래프 아래의 올바른 위치에 레이블을 맞추는 데 문제가 있습니다. 은이 코드를 사용하고 있습니다 :레이블이 히스토그램의 빈 센터에 맞지 않습니다.

![# Category names 
my.names <- c("test1", "test2", "test3", "test4", "test5", "test6") 

# Example data 
data <- c(191,33,12,254,22,74) 

# Normalize the example data as a percentage of the total 
data.norm <- data/sum(data) 

# Use barplot to plot the results 
barplot(data.norm, beside=TRUE, col=c("grey10","grey20","grey30","grey40","grey50","grey60")) 
text(1:6, par("usr")[3], labels=my.names, srt=45, pos=2, xpd=TRUE,offset=0.01)][2] 

x 축 값이 반드시 interger 값 아니다 감사

+0

막대가 1 : 6에서 그려지지 않습니다. barplot 함수에서 실제 중간 점을 도출 할 수 있습니다. [this] (http://stackoverflow.com/a/25037416/2516066) 대답을 살펴보십시오. – koekenbakker

+0

아마 이것은'hist'보다는'barplot'을 직접 참조하기 때문에 더 나은 dup입니다 : http://stackoverflow.com/questions/18634431/r-in-barplot-midpoints-are-not-centered-wrt-bars . 나는 누군가가 더 나은 dup을 아는 경우에 대비해서 스스로를 닫지 않았다. – MrFlick

답변

1

도와주세요. barplot 함수는 플로팅하는 동안 사용 된 x 값을 반환합니다. 시도해보십시오

bp<-barplot(data.norm, beside=TRUE, col=c("grey10","grey20","grey30","grey40","grey50","grey60")) 
text(bp, par("usr")[3], labels=my.names, srt=45, pos=2, xpd=TRUE,offset=0.01) 

대신에보십시오.

enter image description here