簡體   English   中英

使用因子水平作為條形圖中的標簽

[英]Using factor levels as Labels in barplot

我之前以不同的格式問過這個問題,並且得到了部分有效的答案。 我有一個數據框“count_df2”,它有兩個變量和一個具有 12 個級別的因子“標簽”。

TYPES_OF_COMPANIES                  COUNT_OF_COMPANIES                           LABELS
AIM-Listed                                 876                                     AIM
Charitable-organisation                     82                                   Charity
Industrial-Provident                        50                                     I-P
Limited-Partnership                          2                                     L-P
Limited by Guarantee                       277                                     L-G
Limited Liability Partnership              167                                     LLP
Listed-LSE                                1131                                   L-LSE
Not-Companies-Act                           75                                     NCA
Private Limited Company                   1163                                     PLC
Public-Unlisted                            418                                    P-UL
Royal-Charter                                5                                      RC
Unlimited                                  111                                      UL

我想開發一個條形圖,將因子標簽值作為條形的標簽。 我可以使用條形圖

barplot(count_df2$COUNT_OF_COMPANIES,xlab='TYPE_OF_COMPANIES',
      ylab='COUNT_OF_COMPANIES',
      main='Number of Different Types of Companies in the database') 

但我正在努力在不使用 names.arg 的情況下獲取標簽

有人可以幫忙嗎? 提前致謝

你在找嗎

barplot(setNames(count_df2[[2]], count_df2[[3]]),
        xlab = 'TYPE_OF_COMPANIES',
        ylab = 'COUNT_OF_COMPANIES',
        main = 'Number of Different Types of Companies in the database') 

在此處輸入圖片說明


數據

count_df2 <- structure(list(TYPES_OF_COMPANIES = c("AIM-Listed", "Charitable-organisation", 
"Industrial-Provident", "Limited-Partnership", "Limited by Guarantee", 
"Limited Liability Partnership", "Listed-LSE", "Not-Companies-Act", 
"Private Limited Company ", "Public-Unlisted", "Royal-Charter", 
"Unlimited"), COUNT_OF_COMPANIES = c(876L, 82L, 50L, 2L, 277L, 
167L, 1131L, 75L, 1163L, 418L, 5L, 111L), LABELS = c("AIM", "Charity", 
"I-P", "L-P", "L-G", "LLP", "L-LSE", "NCA", "PLC", "P-UL", "RC", 
"UL")), class = "data.frame", row.names = c(NA, -12L))

count_df2
#>               TYPES_OF_COMPANIES COUNT_OF_COMPANIES  LABELS
#> 1                     AIM-Listed                876     AIM
#> 2        Charitable-organisation                 82 Charity
#> 3           Industrial-Provident                 50     I-P
#> 4            Limited-Partnership                  2     L-P
#> 5           Limited by Guarantee                277     L-G
#> 6  Limited Liability Partnership                167     LLP
#> 7                     Listed-LSE               1131   L-LSE
#> 8              Not-Companies-Act                 75     NCA
#> 9       Private Limited Company                1163     PLC
#> 10               Public-Unlisted                418    P-UL
#> 11                 Royal-Charter                  5      RC
#> 12                     Unlimited                111      UL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM