Announcement

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

  • Graph hbar with staplot

    Hello everyone,

    I am having a problem with -staplot-

    I would like to produce the figure attached. In the y-axis, we have the different indicators (the variable is called "indicateurs") and each indicator is displayed in the group (the variable is called "dimensions") that it belongs to. In the x-axis, we have the percentage of the indicator (the variable is called "pourcentage"). In the data can be found below:

    My data look like this:

    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str21 dimensions str48 indicateurs float pourcentage byte tag
    "Nutrition" "Retard de croissance modéré" 37.76 1
    "Nutrition" "Retard de croissance sévère" 18.8 1
    "Nutrition" "Émancipation modéré" 13.94 1
    "Nutrition" "Émancipation sévère" 4.5 1
    "Nutrition" "Insuffisance pondérale modéré" 29.16 1
    "Nutrition" "Insuffisance pondérale sévère" 11.1 1
    "Nutrition" "Allaitement exclusif" 83.8 1
    "Santé" "Moustiquaire imprégnée d’insecticide" 45.66 1
    "Santé" "Accouchement assisté par un personnel de santé" 65.85 1
    "Santé" "Moustiquaire imprégnée d’insecticide" 73.09 0
    "Santé" "Mortalité" 13.96 1
    "Protection" "Extrait de naissance" 77.41 1
    "Protection" "Garde inadéquate de l’enfant" 64.21 1
    "Eau et assainissement" "Accès à une source d'eau améliorée" 39.96 1
    "Eau et assainissement" "Accès à l'assainissement amélioré" 87.57 1
    "Habitation" "Structure du logement" 92.4 1
    "Habitation" "Promiscuité" 28.28 1
    "Habitation" "Accès à l’électricité" 93.25 1
    end


    I had typed the following command :

    catplot indicateurs dimensions , percent( pourcentage) var1opts(label(ang(45)))


    But it is so messy and not close to the attached Figure done in Excel.

    Any help will be greatly appreciated.


    Thank you in advance!

    Attached Files

  • #2
    What is staplot and what does it have to do with the question?

    As for catplot, that's my command from SSC and if you prefer your graph from MS Excel, that's fine by me. Emulating MS Excel is not my game and in any case Excel does a great job at that. I don't willingly recommend ang(45) in any case.

    Comment


    • #3
      Dear Nick,

      Sorry for the confusion. I wanted to say -catplot-. The problem is that when you have several figures, doing this in Excel is time-consuming. In my case, I have several figures and I would like to save time and do it in Stata with your command -catplot-

      Please any suggestion on how to do it with -catplot-?

      Thanks

      Comment


      • #4
        Looking at it more closely, catplot really doesn't seem to apply.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str21 dimensions str48 indicateurs float pourcentage byte tag
        "Nutrition" "Retard de croissance modéré" 37.76 1
        "Nutrition" "Retard de croissance sévère" 18.8 1
        "Nutrition" "Émancipation modéré" 13.94 1
        "Nutrition" "Émancipation sévère" 4.5 1
        "Nutrition" "Insuffisance pondérale modéré" 29.16 1
        "Nutrition" "Insuffisance pondérale sévère" 11.1 1
        "Nutrition" "Allaitement exclusif" 83.8 1
        "Santé" "Moustiquaire imprégnée d'insecticide" 45.66 1
        "Santé" "Accouchement assisté par un personnel de santé" 65.85 1
        "Santé" "Moustiquaire imprégnée d'insecticide" 73.09 0
        "Santé" "Mortalité" 13.96 1
        "Protection" "Extrait de naissance" 77.41 1
        "Protection" "Garde inadéquate de l'enfant" 64.21 1
        "Eau et assainissement" "Accès à une source d'eau améliorée" 39.96 1
        "Eau et assainissement" "Accès à l'assainissement amélioré" 87.57 1
        "Habitation" "Structure du logement" 92.4 1
        "Habitation" "Promiscuité" 28.28 1
        "Habitation" "Accès à l'électricité" 93.25 1
        end
        
        set scheme s1color
        graph hbar (asis) pourcentage if tag, bar(1, fcolor(none)) over(indicateurs, label(labsize(small))) over(dimensions, label(labsize(small))) nofill blabel(bar) ysc(r(., 113))
        Click image for larger version

Name:	french.png
Views:	1
Size:	41.7 KB
ID:	1635732



        That's not great but you could make progress

        1. Shortening some text.

        2. Accepting some rounding of percents, or omitting that altogether.
        Last edited by Nick Cox; 09 Nov 2021, 13:01.

        Comment


        • #5
          Dear Nick,

          Thanks a lot. This works well.

          I am so grateful

          Regards

          Pythagore

          Comment

          Working...
          X