2014-09-10 1 views
0

toupper으로 전화 하시려면 aesggplot2으로 전화하십시오. 예를 들어 PlantGrowth을 사용하면 변수 group을 모두 대문자로 변경하고 싶습니다. x 대문자를 모두 대문자로 바꿀 수 있었지만 x 축 제목은 이상한 제목을 사용합니다. 수동으로 x 축 제목을 삭제할 수 있지만 더 쉬운 방법이있는 것처럼 보입니다.ggplot2 aes에서 toupper 사용

편집 1 : 데이터 프레임의 데이터를 변경하지 말아야한다는 것을 명시해야합니다 (예 : d$group <- toupper(d$group)). 가능한 경우 aes 문 내에서 라벨을 변경하고 싶습니다.

library (ggplot2) 
d <- PlantGrowth 
p <- ggplot() + geom_bar (data=d, aes(toupper(x=group),y=weight),stat='identity') 
p <- p + theme (axis.title.x=element_blank()) #workaround to drop x axis title 
p 

감사 -cherrytree

+0

을 변경하지 않습니다 그룹, 당신은 'd $ group <- toupper (d $ group)'전에 할 수있다. u 그림을 그려. – jazzurro

+0

'p + labs (x = 'Group')' – topchef

답변

1

사용 levels()

library (ggplot2) 
d <- PlantGrowth 
levels(d$group) = toupper(levels(d$group)) 
ggplot() + geom_bar(data=d, aes(x=group,y=weight), stat='identity') 

편집 : 당신은 x 축 제목을 유지하려면 는 data.frame 버전

library (ggplot2) 
d <- PlantGrowth 
ggplot() + geom_bar(data=d, aes(x=group,y=weight), stat='identity') + scale_x_discrete(label = toupper(levels(d$group))) 
+0

으로 축을 포함한 모든 제목을 덮어 쓸 수 있습니다. 기술적으로'레벨 <-'을 사용하고 있습니다. –

+0

데이터 프레임 내에서 데이터를 변경하지 않을 것입니다. 나는 'aes'안에'toupper '를 사용하는 방법이있을 것이라고 생각했다. – cherrytree

+0

데이터를 변경하지 않는 솔루션에 대한 편집 참조. – Vlo