Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • graph bar: only labels from one variable in bold

    Hi. I have the dataset below for which I generated a graph bar. How can I make variable percap_total2 have its legends (both in the x-axis and value labels) in bold? Basically I would like only "Brasil" and its value to be in bold.

    Code:
    * Example generated by -dataex-. To install ssc install dataex
    clear
    input int(percap_total1 percap_total2) float(percap_total3 percap_total4 percap_total5 percap_total6 percap_total7 percap_total8 percap_total9 percap_total10) str33 loc_port
    1457    .        .        .         .        .        .         .       .         . "Argentina"                        
    4400    .        .        .         .        .        .         .       .         . "Austrália"                       
    5183    .        .        .         .        .        .         .       .         . "Áustria"                         
    4939    .        .        .         .        .        .         .       .         . "Bélgica"                         
     450    .        .        .         .        .        .         .       .         . "Bolívia"                         
       . 1431        .        .         .        .        .         .       .         . "Brasil"                           
    4921    .        .        .         .        .        .         .       .         . "Canadá"                          
    1950    .        .        .         .        .        .         .       .         . "Chile"                            
     861    .        .        .         .        .        .         .       .         . "Colômbia"                        
    1339    .        .        .         .        .        .         .       .         . "Costa Rica"                       
    2534    .        .        .         .        .        .         .       .         . "República Checa"                 
    5144    .        .        .         .        .        .         .       .         . "Dinamarca"                        
       .    .        .        . 1098.6072        .        .         .       .         . "Extremo Oriente e Pacífico"      
    1028    .        .        .         .        .        .         .       .         . "Equador"                          
     598    .        .        .         .        .        .         .       .         . "El Salvador"                      
    1946    .        .        .         .        .        .         .       .         . "Estônia"                         
       .    .        .        .         . 2798.714        .         .       .         . "Europa e Ásia Central"           
    4101    .        .        .         .        .        .         .       .         . "Finlândia"                       
    4741    .        .        .         .        .        .         .       .         . "França"                          
       .    .        . 5292.714         .        .        .         .       .         . "G7"                               
    5532    .        .        .         .        .        .         .       .         . "Alemanha"                         
    2352    .        .        .         .        .        .         .       .         . "Grécia"                          
     487    .        .        .         .        .        .         .       .         . "Guatemala"                        
     370    .        .        .         .        .        .         .       .         . "Honduras"                         
    2031    .        .        .         .        .        .         .       .         . "Hungria"                          
    4205    .        .        .         .        .        .         .       .         . "Islândia"                        
    5371    .        .        .         .        .        .         .       .         . "Irlanda"                          
    2560    .        .        .         .        .        .         .       .         . "Israel"                           
    3445    .        .        .         .        .        .         .       .         . "Itália"                          
    4286    .        .        .         .        .        .         .       .         . "Japão"                           
       .    .        .        .         .        . 948.9063         .       .         . "América Latina e Caribe"         
    1683    .        .        .         .        .        .         .       .         . "Letônia"                         
    6530    .        .        .         .        .        .         .       .         . "Luxemburgo"                       
    1081    .        .        .         .        .        .         .       .         . "México"                          
       .    .        .        .         .        .        . 1419.9524       .         . "Oriente Médio e Norte da África"
    5579    .        .        .         .        .        .         .       .         . "Países Baixos"                   
    3648    .        .        .         .        .        .         .       .         . "Nova Zelândia"                   
     432    .        .        .         .        .        .         .       .         . "Nicarágua"                       
       .    .        .        .         .        .        .         .       .         . "América do Norte"                
    7024    .        .        .         .        .        .         .       .         . "Noruega"                          
       .    . 3972.657        .         .        .        .         .       .         . "OCDE"                             
    1588    .        .        .         .        .        .         .       .         . "Panamá"                          
     738    .        .        .         .        .        .         .       .         . "Paraguai"                         
     683    .        .        .         .        .        .         .       .         . "Peru"                             
    1757    .        .        .         .        .        .         .       .         . "Polônia"                         
    2712    .        .        .         .        .        .         .       .         . "Portugal"                         
    2216    .        .        .         .        .        .         .       .         . "Eslováquia"                      
    2806    .        .        .         .        .        .         .       .         . "Eslovênia"                       
       .    .        .        .         .        .        .         . 411.375         . "Sul da Asia"                      
    2835    .        .        .         .        .        .         .       .         . "Coreia do Sul"                    
    3363    .        .        .         .        .        .         .       .         . "Espanha"                          
       .    .        .        .         .        .        .         .       . 282.41666 "África Subsaariana"              
    5550    .        .        .         .        .        .         .       .         . "Suécia"                          
    7465    .        .        .         .        .        .         .       .         . "Suíça"                          
    1029    .        .        .         .        .        .         .       .         . "Peru"                             
    4285    .        .        .         .        .        .         .       .         . "Reino Unido"                      
    9839    .        .        .         .        .        .         .       .         . "Estados Unidos"                   
    2038    .        .        .         .        .        .         .       .         . "Uruguai"                          
     590    .        .        .         .        .        .         .       .         . "Venezuela"                        
    end
    Code generating the graph
    Code:
    program colorpalette_ieps
        c_local P #ffffff,#000000,#666666,#808080,#b3b3b3,#e6e6e6, ///
        #f4d26e,#ffc20e,#d76f2c,#be4345,#632956, ///
        #2f447d,#34679a,#2b7b6f,#97c471
        c_local I branco,preto,cinza_70,cinza_50,cinza_30,cinza_10, ///
        amarelo_claro,amarelo,laranja_escuro,vermelho,roxo, ///
        azul_escuro,azul,verde_azul,verde    
    end
    
    colorpalette ieps
    
    grstyle init
    grstyle set color ieps, select(5 8 3 3 2 2 2 2 2 2 2)
    
    graph bar percap_total1 percap_total2 percap_total3 percap_total4 percap_total5 ///
    percap_total6 percap_total7 percap_total8 percap_total9 percap_total10, nofill ///
    over(loc_port, label(angle(90) labsize(small)) sort(percap_total) descending) ///
    ytitle("") yscale(off) ylab(10400, nogrid) ///
    blabel(total, orientation(vertical) size(small) format(%9.0f)) ///
    ysize(9) xsize(18) graphregion(color(white)) legend(off) name(Fig3_PainelA,replace)

  • #2
    Code:
    replace loc_port="{bf:Brasil}" if loc_port=="Brasil"
    Last edited by Andrew Musau; 16 Sep 2019, 05:38.

    Comment


    • #3
      Many thanks Andrew Musau! I would also like to have the number label above the bar in bold for Brasil (e.g. 1431 in the graph). How could I do so?

      Comment


      • #4
        graph bar restricts what you can include as bar labels, so the solution would be to switch to twoway bar. However, there is an inefficient work-around that would involve first getting rid of the specific bar label and using the text option to insert your own. Below, I use Chinese characters to achieve the former, but you can look at a better way.

        Code:
        graph bar percap_total1 percap_total2 percap_total3 percap_total4 percap_total5 ///
        percap_total6 percap_total7 percap_total8 percap_total9 percap_total10, nofill ///
        over(loc_port, label(angle(90) labsize(small)) sort(percap_total) descending) ///
        ytitle("") yscale(off) ylab(10400, nogrid) text(2700 4.3 "解解解解", size(small) ///
        orient(vertical) color(white)) text(2750 4.3 "解解解解", size(small) orient(vertical) color(white)) ///
        text(2450 4.3 "{bf:1431}",orient(vertical) size(small)) ///
        blabel(total, orientation(vertical) size(small) format(%9.0f))  ///
        ysize(9) xsize(18) graphregion(color(white)) legend(off) name(Fig3_PainelA,replace)

        Comment


        • #5
          Your graph seems to mix countries and regions quite arbitrarily. Vertical axis labels rarely improve readability as much as you hope. I would split the data and use horizontal bars. This is naturally nothing to do with your specific queries so far.

          Comment

          Working...
          X