간단한 막대 그림을 ggplot2
에 플로팅하는 데 문제가 있습니다. 각 막대 위에 값의 레이블을 표시하고 싶지만 각 국가를 참조하는 여러 개의 데이터 요소에 대해 내 x 축을 따라 여러 요소 변수가있는 경우 서로 나란히 따라 플롯 막대에 postion=position_dodge
을 사용하고 있습니다.피할 수있는 막대 그래프 값
ggplot(maln_complete_recent_melt, aes(x=COUNTRY, y=percent, fill=location)) + geom_bar(position="dodge", colour="black") +labs(title="Percentage of malnoursihed children according to height for age", fill="DHS Survey") + geom_text(aes(label=round(percent))) + scale_x_discrete(labels=c(paste(maln_complete_recent_melt$COUNTRY, maln_complete_recent_melt$Year, sep="")))
:
현재 내가 x 축을 따라 각 막대 위에 중심 각 값을 원하는 반면, 내 X 축을 따라
COUNTRY
의 이름 위에 중심으로 모든 값을 얻고 다음 코드를 사용하여
는 그리고 이것은 내 음모 현재 모습입니다 :
나는 이것이 정말 간단한 일이지만, 포럼을 저인망 및 R 책의 번호를 상담 한거야, 내가 무엇을 찾을 수없는 I 찾고있어.
여기에 복제를 위해 내 데이터의 :
structure(list(COUNTRY = structure(c(4L, 10L, 5L, 8L, 14L, 13L,
9L, 2L, 11L, 1L, 6L, 7L, 12L, 3L, 4L, 10L, 5L, 8L, 14L, 13L,
9L, 2L, 11L, 1L, 6L, 7L, 12L, 3L, 4L, 10L, 5L, 8L, 14L, 13L,
9L, 2L, 11L, 1L, 6L, 7L, 12L, 3L, 4L, 10L, 5L, 8L, 14L, 13L,
9L, 2L, 11L, 1L, 6L, 7L, 12L, 3L, 4L, 10L, 5L, 8L, 14L, 13L,
9L, 2L, 11L, 1L, 6L, 7L, 12L, 3L, 4L, 10L, 5L, 8L, 14L, 13L,
9L, 2L, 11L, 1L, 6L, 7L, 12L, 3L), class = "factor", .Label = c("Swaziland",
"Namibia", "Zimbabwe", "Comoros", "Kenya", "Tanzania", "Uganda",
"Lesotho", "Mozambique", "Ethiopia", "Rwanda", "Zambia", "Malawi",
"Madagascar")), Year = structure(c(5L, 23L, 20L, 21L, 20L, 14L,
12L, 18L, 15L, 18L, 14L, 17L, 19L, 22L, 5L, 23L, 20L, 21L, 20L,
14L, 12L, 18L, 15L, 18L, 14L, 17L, 19L, 22L, 5L, 23L, 20L, 21L,
20L, 14L, 12L, 18L, 15L, 18L, 14L, 17L, 19L, 22L, 5L, 23L, 20L,
21L, 20L, 14L, 12L, 18L, 15L, 18L, 14L, 17L, 19L, 22L, 5L, 23L,
20L, 21L, 20L, 14L, 12L, 18L, 15L, 18L, 14L, 17L, 19L, 22L, 5L,
23L, 20L, 21L, 20L, 14L, 12L, 18L, 15L, 18L, 14L, 17L, 19L, 22L
), class = "factor", .Label = c("1992", "1993", "1994", "1995",
"1996", "1997", "1998", "1999", "2000", "2000/1", "2001/2", "2003",
"2003/4", "2004", "2005", "2005/6", "2006", "2006/7", "2007",
"2008/9", "2009", "2010", "2011")), location = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L), .Label = c("Urban", "Rural", "Total", "Capital.City",
"Urban.Non.slum", "Urban.Slum"), class = "factor"), percent = c(29.9107142857143,
31.5, 26.4, 30.2, 43.4, 37.8, 29.2, 23.8, 33.1, 23.1, 25.8, 25.5,
39, 27.5, 35.0071736011478, 46.2, 37.1, 41, 50.9, 49.2, 45.7,
31.4, 47.2501049401341, 30, 40.5, 39.5, 47.9, 33.4, 33.8, 44.4,
35.3, 39.2, 50.1, 47.8, 41, 29, 45.3, 28.9, 37.7, 38.1, 45.4,
32, NA, 22, 28.5, 31.7, 46.8, NA, 20.6, NA, 29.2, NA, 16.9, NA,
37.2, 29, 21.6666666666667, 10.7799374501425, 16.0100871430598,
21.2511075992408, 23.7772452013661, 23.8620542603877, 8.15543422154615,
12.5321762341041, 13.5923403336176, 13.0494984481826, 16.4644101423357,
21.5426476162423, 27.4144189089535, 16.2492480072194, 32.9268292682927,
27.8790407698325, 25.0985529949154, 26.2950824206824, 37.9693371617388,
40.5197947988247, 29.3593820697417, 28.5099311066166, 36.0242620139593,
20.7853672439948, 28.5877166151249, 22.8001055045257, 35.5434627654004,
28.0633523545878)), .Names = c("COUNTRY", "Year", "location",
"percent"), row.names = c(NA, -84L), class = "data.frame")
이 http://stackoverflow.com/questions/6017460/ggplot에서보세요 -geom-text-with-dodged-barplot – Beasterfield
@ Beasterfield, 네, 고마워요! 'position = position_dodge (width = 0.9)'가 트릭을 만들었습니다. –