따라서 데이터 프레임은 다음과 같습니다.
results <- data.frame(Name=factor(c("Mark", "Mark", "Sue", "Sue")),
Tutor= factor(c("Eric", "Eric", "Richard", "Richard")),
Test= factor(c("Maths","English","Maths", "English")),
Score= c(100,91,88,71),
Percent=c(100,91,100,80.7),
school.year= c(2,2,5,5))
여러 변수로 축에 레이블을 지정하는 첫 번째 제안 된 솔루션을 사용했습니다.
results$label <- paste(results$Name,results$Tutor,sep='\n')
ggplot(results, aes(y=Percent, x=label, colour=Test, fill=Test)) +
geom_bar(stat='identity', position='dodge') +
ggtitle('Test Results') +
ylab('Percent')
이 그래프를 얻습니다
이제이 그래프에 표시된대로 x 축 레이블의 첫 번째 행만 회전 (90 °)하고 싶습니다.
이 작업을 수행하는 방법이 있습니까? 많은 감사
최선의 방법은 아니지만 annote()
from ggplot
을 사용 하여이 작업을 수행 할 수 있습니다 . 나는에서 라벨을 변경 Tutor
하고 Name
단지에 Tutor
와 대한 텍스트 레이블을 추가 Name
.
results$label <- paste(results$Tutor)
row1 <- results$Name
ggplot(results, aes(y=Percent, x=label, colour=Test, fill=Test)) +
geom_bar(stat='identity', position='dodge') +
ggtitle('Test Results') +
annotate(geom = "text", x=results$label, y=-5, label=row1, size=3, angle = 90)+
ylab('Percent')
물론 추가 된 텍스트 레이블의 크기와 위치를 조정할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다