2014-02-27 10 views
2

, 그것은 백분율로 해석하고 후자 적어도 축 라벨의 각 증가 후 "%"를 추가 (또는 한 나는 현재 다음 코드R의 막대 그래프에 축에 백분율 기호를 추가하려면 어떻게합니까?

testdata <- data.frame(one=c(.25),two=c(.25),three=c(.5)) 

b <- barplot(t(testdata*100), col=c("darkred","darkblue","darkgoldenrod"), cex.axis=0.7,horiz=TRUE,border=NA) 
text(b, x = c(.125,.375,.75)*100, c("Label1", "Label2", "Label3"), cex=.7, col="white") 
text(b, x = c(0,20,40,60,80,100), y=0, labels = rep("%",6), cex=.7) 

을 가지고 있지만 내가 대신 100을 곱 필요없이 원하는).

답변

4

barplot() (그림 : axes = FALSE)을 사용하여 플로팅 할 때 축을 억제 한 다음 눈금과 해당 레이블과 함께 배치 할 위치를 제어 할 수있는 축을 손으로 추가하는 것이 더 쉽습니다. 아래의 코드는

enter image description here

생산이

b <- barplot(t(testdata), col = c("darkred","darkblue","darkgoldenrod"), 
      horiz = TRUE, border = NA, axes = FALSE) 
labs <- seq(0, 1, by = 0.25) 
text(b, x = c(0.125, 0.375, 0.75), labels = c("Label1", "Label2", "Label3"), 
    cex = 0.7, col = "white") 
axis(side = 1, at = labs, labels = paste0(labs * 100, "%"), cex.axis = 0.7) 

당신이 얻을 찾고 무엇인가요 할 수있는 한 방법입니다?

관련 문제