2012-07-11 6 views
2

이 주제에 대한 다른 게시물을 검색했지만 내 문제를 파악할 수 없습니다. 브라질 정부 기관에 대한 예산 데이터를 보유하고 있으며 대행사 유형을 분류했습니다. 내 음모를 생산하기 위해, 나는이 작업을 수행 :ggplot2 스트립 텍스트 라벨 facet_wrap

g <- ggplot(data=totalex.df, aes(x=year, y=totalex.billions)) 

g + 
geom_line(aes(colour=factor(agency.type))) + 
facet_wrap(agency.type ~ unit, ncol=6) + 
opts(strip.text.x = theme_text(size=2)) + 
opts(axis.text.x=theme_text(size=4)) + 
opts(legend.position="none") + 
scale_y_sqrt("total expenditure (billions)") 

내 문제, 내면 라벨은 이제 두 가지 정보가 들어 기관 유형과 위의 코드로 생성되는 unit-- this is a pdf of the graph의 이름을. 나는 단지 그것이 유닛의 이름을 포함하기를 원한다. 그러나 facet_wrap 명령에서 agency.type을 삭제하면 ggplot은 대행사의 주문을 잃게됩니다.

dput(totalex.df)의 출력은 상당히 긴하지만, 여기가 처음 100 명 관찰

> dput(totalex.df.short) 
structure(list(year = c(2006, 2006, 2006, 2006, 2006, 2006, 2006, 
2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 
2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 
2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 
2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 
2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 
2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2007, 2007, 
2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 
2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 
2007, 2007, 2007, 2007, 2007), totalex = c(312685301, 46492724, 
85210069, 1478565787, 193941282, 260659307, 8327549603, 0, 18474604, 
91006939, 53538760, 91800981, 402711174, 1290377603, 978348209, 
48360776, 24676283, 89820385, 1038592122, 5364674136, 127383506, 
7552311, 3847705355, 232732854, 34317692, 351714802, 156996087, 
104782402, 0, 47741444, 475303761, 229743044, 102577783, 19106706, 
78619935, 0, 730381485, 998733938, 110785185, 37114540, 108530853, 
0, 0, 0, 2660417864, 169144966, 104350391, 1038914804, 336660855, 
11995616, 0, 0, 9085111, 0, 5281402, 138708048, 11283655, 478421026, 
221976619, 95680527, 8270558, 890375094, 0, 156563720, 198830207, 
286909569, 5525428151, 734738984, 218905808, 1120014693, 859180, 
359873525, 50214197, 95572929, 1628550454, 227051722, 286610734, 
8868199792, 17388668, 19551190, 101047436, 58123546, 101878908, 
423760647, 1019623567, 1061465081, 49559379, 24278026, 110344326, 
1145862548, 7610896352, 163919333, 8376104, 4355447941, 282679957, 
45506963, 392551882, 208594544, 122420822, 0), agency.type = structure(c(NA, 
NA, NA, 3L, 1L, 1L, 7L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 1L, 1L, 1L, 
3L, 1L, 6L, 1L, 1L, 7L, 1L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 3L, 
1L, 3L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 5L, 3L, 1L, 5L, 3L, 1L, 1L, 
1L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 4L, 1L, 1L, 2L, 
1L, 1L, 3L, 1L, 1L, 3L, NA, NA, NA, 3L, 1L, 1L, 7L, 1L, 1L, 1L, 
1L, 1L, 4L, 1L, 1L, 1L, 1L, 3L, 1L, 6L, 1L, 1L, 7L, 1L, 3L, 3L, 
1L, 3L, 1L), .Label = c("Delivery", "Guidance for policy formulation/Research", 
"Regulatory", "Regulatory/Delivery", "Regulatory/Delivery", 
"Transfer/delivery", "Transfer/Regulatory/Deliver"), class = "factor"), 
    unit = structure(c(29L, 28L, 27L, 17L, 21L, 66L, 55L, 5L, 
    69L, 25L, 33L, 36L, 44L, 45L, 9L, 34L, 68L, 13L, 6L, 61L, 
    53L, 65L, 51L, 31L, 41L, 39L, 37L, 49L, 22L, 58L, 47L, 71L, 
    40L, 60L, 19L, 18L, 64L, 10L, 62L, 59L, 42L, 7L, 11L, 4L, 
    52L, 32L, 38L, 8L, 54L, 20L, 12L, 24L, 1L, 63L, 3L, 16L, 
    57L, 70L, 43L, 15L, 2L, 46L, 30L, 35L, 56L, 23L, 48L, 26L, 
    14L, 50L, 67L, 29L, 28L, 27L, 17L, 21L, 66L, 55L, 5L, 69L, 
    25L, 33L, 36L, 44L, 45L, 9L, 34L, 68L, 13L, 6L, 61L, 53L, 
    65L, 51L, 31L, 41L, 39L, 37L, 49L, 22L), .Label = c("Administrative Council of Economic Defense (CADE)        ", 
    "Air Force Real Estate Funding Agency (CFIAE)         ", 
    "Alexandre Gusmao Foundation (FUNAG)           ", 
    "Amazon Development Superintendency (SUDAM)          ", 
    "Applied Economic Research Institute (IPEA)          ", 
    "Brazilian Agricultural Research Corporation (EMBRAPA)       ", 
    "Brazilian Communication Company (EBC)           ", 
    "Brazilian Company of Urban Railway (CBTU)          ", 
    "Brazilian Institute of Environment and Renewable Natural Resources (IBAMA)  ", 
    "Brazilian Institute of Geography and Statistics (IBGE)       ", 
    "Brazilian Institute of Museums (IBRAM)           ", 
    "Brazilian Military Material Industry (IMBEL)         ", 
    "Brazilian Securities Comission (CVM)           ", 
    "Brazilian Space Agency (AEB)             ", 
    "Brazilian Tourism Company (EMBRATUR)           ", 
    "Brazilian Urban Railway (TRENSUBR)            ", 
    "Central Bank (BACEN)               ", 
    "Chico Mendes Institute (ICMBio)            ", 
    "Civil Aviation National Agency (ANAC)           ", 
    "Cultural Foundation Palmares             ", 
    "Dom Pedro II School               ", 
    "Energy Research Company (EPE)             ", 
    "Engineering, Construction and Railway (VALEC)         ", 
    "Excellence center in advanced electronic technology (CEITEC)     ", 
    "Federal Centre of Educational Technology Celso Suckow da Fonseca (CEFET-RJ) ", 
    "Graduate students improvement coordination (CAPES)        ", 
    "Hospital Cristo Redentor S.A.             ", 
    "Hospital F\x90mina S.A               ", 
    "Hospital Nossa Senhora da Concei\x8d\x8bo S.A          ", 
    "Housing Building Fund for Mariners (CCCPMC)         ", 
    "Indigenous National Foundation (FUNAI)           ", 
    "Institute of the Historical and Artistic National Heritage (IPHAN)    ", 
    "Joaquim Nabuco Foundation              ", 
    "Jorge Duprat Figueiredo Foundation (FUNDACENTRO)        ", 
    "Manaus Free Trade Zone Superintendency (SUFRAMA)        ", 
    "Minas Gerais Federal Centre of Educational Technology (CEFET-MG)    ", 
    "Mineral Resources Research Institute (CPRM)         ", 
    "National Agency of Land Transport (ANTT)          ", 
    "National Agency of Sanitary Supervision (ANVISA)        ", 
    "National Agency of Supplementary Health (ANS)         ", 
    "National Agency of Water Transport (ANTAQ)         ", 
    "National Agency of Electrical Energy (ANEEL)         ", 
    "National Agency of Oil, Natural Gas and Biofuel (ANP)       ", 
    "National Commission of Nuclear Energy (CNEN)         ", 
    "National Company of Food Supply (CONAB)          ", 
    "National Council of Scientific and Technological Development (CNPq)   ", 
    "National Department of Draught Prevention (DNOCS)        ", 
    "National Department of Infrasctructure Transport (DNIT)      ", 
    "National Department of Mineral Production (DNPM)        ", 
    "National Development Trust (FND)            ", 
    "National Health Foundation (FUNASA)           ", 
    "National Institute of Colonization and Land Reform (INCRA)      ", 
    "National Institute of Industrial Property (INPI)        ", 
    "National Institute of Metrology, Normalization and Industrial Quality (Inmetro)", 
    "National Institute of Social Security (INSS)         ", 
    "National Institute of Studies and Educational Research Anisio Teixeira (INEP) ", 
    "National Institute of Technology Information (ITI)        ", 
    "National Library Foundation             ", 
    "National Movies Agency (ANCINE)            ", 
    "National School of Public Administration Foundation (ENAP)      ", 
    "National Trust of Education Development (FNDE)         ", 
    "National Water Agency (ANA)             ", 
    "Northeast Development Superintendency (SUDENE)         ", 
    "Oswaldo Cruz Foundation (FIOCRUZ)            ", 
    "Ozorio Foundation                ", 
    "Porto Alegre Clinic Hospital             ", 
    "Private Insurance Superintendency (SUSEP)          ", 
    "Rio de Janeiro Botanical Gardens Research Institute       ", 
    "Rui Barbosa House Foundation             ", 
    "Sao Francisco and Parnaiba Valleys Development Company (CODEVASF)    ", 
    "Telecom National Agency (ANATEL)            " 
    ), class = "factor")), .Names = c("year", "totalex", "agency.type", 
"unit"), row.names = c(NA, 100L), class = "data.frame") 
+0

'facet_grid'는 라벨을 변경할 수있는은'labeller' 인수를 가지고 – James

+0

안녕 제임스. 나는 labeller의 주장을 알고 있지만 그것이 어떻게 작동하는지 알 수 없다. stackoverflow에 대한 몇 가지 논의가 있습니다. 예를 들어 [here] (http://stackoverflow.com/questions/10151123/how-to-specify-columns-in-facet-grid-or-how-to-change-labels-in -facet-wrap) 및 [여기] (http://stackoverflow.com/questions/3472980/ggplot-how-to-change-facet-labels?rq = 1) 그러나 직접적인 관련성은없는 것으로 보입니다. – user1519289

+0

패싯의 수와 같은 벡터를 반환하는 2 개의 인수 (변수, 값)의 함수가 필요합니다. 기본값은'label_value'입니다. 원하는 레이블 목록을 반환하고 인수를 무시하는 익명의 함수를 제공 할 수 있습니다. – James

답변

-2

가 재현 그래서 당신이 우리에게 데이터를 제공한다면 도움이 될위한 것입니다. 너무 길지 않다면 dput(totalex.df)의 결과를 질문에 추가 할 수 있습니까?

unit에 대한면을 원하십니까? 또는 당신은 unit & agency.type의 각 조합에 대한면을 원하는가? 모두,이 시도 있다면

facet_wrap(~ unit, ncol=6)

을 : 그냥 unit을의 경우

이 시도 참고

facet_grid(agency.type ~ unit, ncol=6)

을 - facet_wrap을 사용하는 방법에 대한 이해를 얻으려면 및 facet_grid 함수에 대한 자세한 내용은 Hadley의 설명서를 참조하십시오.

내 최초의 생각에

+0

Tommy에게 관심 가져 주셔서 감사합니다. 내가 원하는 것은 각 유닛의 패싯이지만, 패싯은 agency.type에 의해 정렬되어야합니다. 나는 위의'dput (totalex.df)'를 덧붙였다. – user1519289

2

는 달리, 나는 단지 facet_grid하지 facet_wrap을 위해 작동하기 때문에 labeller 여기에 당신을 도울 것입니다 생각하지 않습니다. 오히려 문제는 더 쉬운 방법으로 처리 될 수 있다고 생각합니다. 패싯의 순서는 요소 수준의 순서에 따라 제어되므로 unit의 수준을 agency.type으로 그룹화되도록 재정렬하면 충분합니다.

agency.unit <- unique(totalex.df[c("agency.type", "unit")]) 

totalex.df$unit <- factor(totalex.df$unit, 
    levels = agency.unit[order(agency.unit$agency.type, 
          agency.unit$unit), "unit"]) 

그런 다음이 facet_wrap 그 안에 agency.type을 필요가 없습니다. 전체에서

facet_wrap(~ unit, ncol=6) 

:이 읽을하는 것은 불가능하더라도

ggplot(data=totalex.df, aes(x=year, y=totalex)) + 
    geom_line(aes(colour=factor(agency.type))) + 
    facet_wrap(~ unit, ncol=6) + 
    opts(strip.text.x = theme_text(size=2)) + 
    opts(axis.text.x=theme_text(size=4)) + 
    opts(legend.position="none") + 
    scale_y_sqrt("total expenditure (billions)") 

enter image description here

는 첫 번째 단위는 "공군 부동산 자금 조달기구 (CFIAE이)", "다음이다 알렉산드르 구스마오 재단 (FUNAG) ","응용 경제 연구소 (IPEA) "등

+0

나는 이것이 옳지 않다고 생각한다. Brian (그렇지 않으면 내가 그 길을 따라 어딘가에 잘못 갔다). 나는'geom_line (aes (color = factor (agency.type))) '를 사용하여 다른 유형의 에이전시를 나타 내기 위해 선 색상을 사용했다. 그래서 우리가 원한다면 같은 색깔의 모든 선들이 함께 그룹화 될 것입니다. 문제는 우리가 71 개의 고유 기관과 71 개의 요인을 가지고 있지만 단 7 개의 수준 (의미가있는 경우)이 있다고 생각합니다. – user1519289

+0

덧붙여 말하자면, ggplot2 도움말 파일은'aes_group_order'라는 것을 나타냅니다. 도움말 파일을 읽으면'facet_wrap (~ unit, ncol = 6, aes (order = agency.type)) '과 같은 일을 할 수 있어야하고 이것이 내 문제를 해결할 수 있다고 생각하게 만든다. 하지만 그렇게 보이지는 않습니다. – user1519289

+0

특히 오류는 'nrow : ncol : 2 진수 연산자에 대한 숫자가 아닌 인수'오류입니다. – user1519289