2017-04-11 17 views
1

Rに文字列値ラベル(職業グループ)を持つ変数がありますが、変数の実際の値は数値です。ヒストグラムにラベルを表示する(値)R

変数をヒストグラムとして表示すると、特定の数値に付けられたラベルが表示されます。現在、数値の値を棒に付けることしかできませんでした( "hist(occgroupsn、labels = ) ")TRUE Histogram with numbers

これは私が)汚いコードの(ごめん値ラベルを追加する方法です:

occgroups <- ordered(IscoGroups, 
       levels = c("01", 
          "02", 
          "03", 
          "11", 
          "12", 
          "13", 
          "14", 
          "21", 
          "22", 
          "23", 
          "24", 
          "25", 
          "26", 
          "31", 
          "32", 
          "33", 
          "34", 
          "35", 
          "41", 
          "42", 
          "43", 
          "44", 
          "51", 
          "52", 
          "53", 
          "54", 
          "61", 
          "62", 
          "63", 
          "71", 
          "72", 
          "73", 
          "74", 
          "75", 
          "81", 
          "82", 
          "83", 
          "91", 
          "92", 
          "93", 
          "94", 
          "95", 
          "96"), 
       labels = c("Commissioned armed forces officers" 
          , "Non-commissioned armed forces officers" 
          , "Armed forces occupations, other ranks" 
          , "Chief executives, senior officials and legislators" 
          , "Administrative and commercial managers" 
          , "Production and specialised services managers" 
          , "Hospitality, retail and other services managers" 
          , "Science and engineering professionals" 
          , "Health professionals" 
          , "Teaching professionals" 
          , "Business and administration professionals" 
          , "Information and communications technology professionals" 
          , "Legal, social and cultural professionals" 
          , "Science and engineering associate professionals" 
          , "Health associate professionals" 
          , "Business and administration associate professionals" 
          , "Legal, social, cultural and related associate professionals" 
          , "Information and communications technicians" 
          , "General and keyboard clerks" 
          , "Customer services clerks" 
          , "Numerical and material recording clerks" 
          , "Other clerical support workers" 
          , "Personal service workers" 
          , "Sales workers" 
          , "Personal care workers" 
          , "Protective services workers" 
          , "Market-oriented skilled agricultural workers" 
          , "Market-oriented skilled forestry, fishery and hunting workers" 
          , "Subsistence farmers, fishers, hunters and gatherers" 
          , "Building and related trades workers, excluding electricians" 
          , "Metal, machinery and related trades workers" 
          , "Handicraft and printing workers" 
          , "Electrical and electronic trades workers" 
          , "Food processing, wood working, garment and other craft and related trades workers" 
          , "Stationary plant and machine operators" 
          , "Assemblers" 
          , "Drivers and mobile plant operators" 
          , "Cleaners and helpers" 
          , "Agricultural, forestry and fishery labourers" 
          , "Labourers in mining, construction, manufacturing and transport" 
          , "Food preparation assistants" 
          , "Street and related sales and service workers" 
          , "Refuse workers and other elementary workers")) 

occgroupsn <- as.numeric(occgroups) 
hist(occgroupsn, labels = TRUE) 

それらを表示させるには?それとも私は別のやり方でそれをするべきですか?

編集:ここでは、

SampleVar <- c(1, 1, 2, 2, 2, 2, 3, 3, 3, 4) 
SampleVarLabeled <- ordered(SampleVar, 
        levels = c("1", "2", "3", "4"), 
        labels = c("Commissioned armed forces officers" , 
           "Noncommissioned armed forces officers" , 
           "Armed forces, other ranks" , 
           "Chief executives")) 
SampleVarLabeledn <- as.numeric(SampleVarLabeled) 
hist(SampleVarLabeledn, labels = TRUE) 
+0

である:ここで、私はtableを用いて周波数をカウントしていますか? http://stackoverflow.com/questions/19417760/histogram-of-factor-with-labels-on-frequency-bars – Jealie

+0

あなたのデータは再現性がありません。私たちはIscoGroupsにアクセスすることはできません。この質問には、より小さなサンプルデータセットを使用する必要があります。 –

+0

@Yealieヒストグラムのラベル= TRUEを使用して、私が既に行っていることをポスターが望んでいることを祈っています。 –

答えて

0

[OK]を、私はそれを行うだろう方法は次のとおりです。これは、小さな再現可能なサンプルと同じコードです。 histのフリークエンシーバージョンを使用しているため、barplotをカウントすることもできます。あなたの場合、職業名は非常に長いので、水平の棒グラフを考慮する必要があります。読むのが簡単です。この答えは、あなたの質問に良好な応答

original_par <-par() #make a copy of your par 
par(mar = c(5, 17, 2, 2)) #increase left margin to 17 
counts <- table(SampleVarLabeled) 
barplot(counts, main="Occupation", xlab="Count",horiz=TRUE, las=1) 

par() <- original_par #to go back to original par 

enter image description here

+0

ありがとう、これは多くの助け! –

関連する問題