Announcement

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

  • Replicating a combined graph

    I would like to replicate the attached graph in stata but I have a few challenges
    1. I set scheme to burd but I cannot find the color palates to match this graph
    2. I have drawn the individual graphs but each has a different range for the y-axis so I would like to specify the range to match this graph
    3. I would like to have one continuous x-axis

    NB: all variables are binary.



    I have attached my best attempt at combining the graph but it’s obviously chaotic

    I used the code
    grc1leg anhedonia_SA.gph apathy_SA.gph decreased_sleep_SA.gph fatigue_SA.gph flight_ideas_SA.gph grandiosity_SA.gph hospitalization_SA.gph hypersomnia_SA.gph suicidality_SA.gph , title ("SA") legendfrom(anhedonia_SA.gph) col(7)
    Click image for larger version

Name:	IMG_0997.jpeg
Views:	1
Size:	752.3 KB
ID:	1716517



    Click image for larger version

Name:	IMG_0996.jpeg
Views:	1
Size:	714.4 KB
ID:	1716516

  • #2
    3. I would like to have one continuous x-axis
    You need to create one categorical variable instead of having several variables. We need a data example with at least 2 variables to illustrate possible techniques.

    Code:
    dataex var1- var5
    where you replace "var1" and "var5" with the names of variables in your dataset, ordered from left to right.

    Comment


    • #3
      Originally posted by Andrew Musau View Post

      You need to create one categorical variable instead of having several variables. We need a data example with at least 2 variables to illustrate possible techniques.

      Code:
      dataex var1- var5
      where you replace "var1" and "var5" with the names of variables in your dataset, ordered from left to right.
      Thank you Andrew, here is a sample of the data
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(anhedonia apathy fatigue flight_of_ideas Schizophrenia    Schizoaffective)
      0 0 1 1 0 0
      . 0 . . 0 0
      0 0 . . 0 0
      0 0 . . 0 0
      0 0 . . 0 0
      . 0 . . 0 0
      0 0 . . 0 0
      . 0 . . 0 0
      0 0 . . 1 0
      . 0 . . 0 0
      . 0 . . 0 0
      0 1 1 0 0 0
      0 0 1 1 1 0
      0 0 . 1 1 0
      0 0 1 1 0 0
      0 0 . . 1 0
      0 0 . 1 0 0
      0 0 . 0 0 0
      0 0 . . 0 0
      0 1 . 1 1 0
      0 0 . . 0 0
      0 0 . . 0 0
      0 1 . . 1 0
      0 0 . . 1 0
      0 1 1 0 0 1
      0 0 0 1 1 0
      1 1 1 1 1 0
      . 0 . . 0 0
      0 0 . . 1 0
      . 0 . . 0 0
      0 0 . . 0 0
      . 0 . . 0 0
      0 1 . . 1 0
      0 0 . . 0 0
      . 0 . . 0 0
      0 0 0 1 0 0
      . 0 . . 0 0
      . 0 . . 0 0
      0 1 . . 1 0
      . 0 . . 0 0
      0 0 . . 0 0
      0 1 . . 1 0
      0 1 1 . 0 1
      0 0 . . 0 0
      0 1 . . 1 0
      0 0 . . 0 0
      0 1 1 . 1 0
      . 0 . . 0 0
      0 0 . . 0 0
      0 0 1 1 0 0
      0 1 . . 1 0
      0 0 . . 0 0
      0 0 . . 0 0
      0 1 . 1 1 0
      0 0 1 1 1 0
      . 0 . . 0 0
      . 0 . . 0 0
      0 0 . . 1 0
      . 0 . . 0 0
      0 0 1 1 1 0
      . 0 . . 0 0
      0 0 0 1 1 0
      0 1 1 1 1 0
      0 0 1 1 1 0
      1 0 0 1 0 0
      0 1 . . 1 0
      0 1 . . 0 0
      . 0 . . 0 0
      1 0 0 1 1 0
      0 1 . . 1 0
      0 1 . 0 1 0
      0 1 1 . 1 0
      0 0 0 1 0 0
      0 0 . . 0 0
      0 1 . 0 1 0
      0 1 . . 1 0
      . 0 . . 0 0
      . 0 . . 0 0
      . 0 . . 0 0
      0 1 . . 1 0
      . 0 . . 0 0
      . 0 . . 0 0
      . 0 . . 0 0
      . 0 . . 0 0
      1 0 1 . 0 0
      0 0 . . 0 0
      0 0 . . 0 0
      0 0 . . 1 0
      0 0 . . 0 0
      1 0 1 1 0 0
      0 1 1 1 1 0
      0 0 . . 0 0
      . 0 . . 0 0
      . 0 . . 0 0
      0 0 0 . 1 0
      0 0 . . 0 0
      0 0 1 1 0 0
      . 0 . . 0 0
      0 1 . 1 1 0
      . 0 . . 0 0
      end
      label values anhedonia anhedonia
      label def anhedonia 0 "null", modify
      label def anhedonia 1 "Anhedonia", modify
      label values apathy apathy
      label def apathy 0 "null", modify
      label def apathy 1 " Abulia/apathy", modify
      label values fatigue fatigue
      label def fatigue 0 "null", modify
      label def fatigue 1 "Fatigue", modify
      label values flight_of_ideas ideas
      label def ideas 0 "null", modify
      label def ideas 1 "Flight ideas", modify

      Comment


      • #4
        I assume that the three categories shown are missing, yes and no. Below, a horizontal bar graph allows better placement of the labels. You may change the colors accordingly, these are my best guesses from looking at the attached graph.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float(anhedonia apathy fatigue flight_of_ideas Schizophrenia Schizoaffective)
        0 0 1 1 0 0
        . 0 . . 0 0
        0 0 . . 0 0
        0 0 . . 0 0
        0 0 . . 0 0
        . 0 . . 0 0
        0 0 . . 0 0
        . 0 . . 0 0
        0 0 . . 1 0
        . 0 . . 0 0
        . 0 . . 0 0
        0 1 1 0 0 0
        0 0 1 1 1 0
        0 0 . 1 1 0
        0 0 1 1 0 0
        0 0 . . 1 0
        0 0 . 1 0 0
        0 0 . 0 0 0
        0 0 . . 0 0
        0 1 . 1 1 0
        0 0 . . 0 0
        0 0 . . 0 0
        0 1 . . 1 0
        0 0 . . 1 0
        0 1 1 0 0 1
        0 0 0 1 1 0
        1 1 1 1 1 0
        . 0 . . 0 0
        0 0 . . 1 0
        . 0 . . 0 0
        0 0 . . 0 0
        . 0 . . 0 0
        0 1 . . 1 0
        0 0 . . 0 0
        . 0 . . 0 0
        0 0 0 1 0 0
        . 0 . . 0 0
        . 0 . . 0 0
        0 1 . . 1 0
        . 0 . . 0 0
        0 0 . . 0 0
        0 1 . . 1 0
        0 1 1 . 0 1
        0 0 . . 0 0
        0 1 . . 1 0
        0 0 . . 0 0
        0 1 1 . 1 0
        . 0 . . 0 0
        0 0 . . 0 0
        0 0 1 1 0 0
        0 1 . . 1 0
        0 0 . . 0 0
        0 0 . . 0 0
        0 1 . 1 1 0
        0 0 1 1 1 0
        . 0 . . 0 0
        . 0 . . 0 0
        0 0 . . 1 0
        . 0 . . 0 0
        0 0 1 1 1 0
        . 0 . . 0 0
        0 0 0 1 1 0
        0 1 1 1 1 0
        0 0 1 1 1 0
        1 0 0 1 0 0
        0 1 . . 1 0
        0 1 . . 0 0
        . 0 . . 0 0
        1 0 0 1 1 0
        0 1 . . 1 0
        0 1 . 0 1 0
        0 1 1 . 1 0
        0 0 0 1 0 0
        0 0 . . 0 0
        0 1 . 0 1 0
        0 1 . . 1 0
        . 0 . . 0 0
        . 0 . . 0 0
        . 0 . . 0 0
        0 1 . . 1 0
        . 0 . . 0 0
        . 0 . . 0 0
        . 0 . . 0 0
        . 0 . . 0 0
        1 0 1 . 0 0
        0 0 . . 0 0
        0 0 . . 0 0
        0 0 . . 1 0
        0 0 . . 0 0
        1 0 1 1 0 0
        0 1 1 1 1 0
        0 0 . . 0 0
        . 0 . . 0 0
        . 0 . . 0 0
        0 0 0 . 1 0
        0 0 . . 0 0
        0 0 1 1 0 0
        . 0 . . 0 0
        0 1 . 1 1 0
        . 0 . . 0 0
        end
        label values anhedonia anhedonia
        label def anhedonia 0 "null", modify
        label def anhedonia 1 "Anhedonia", modify
        label values apathy apathy
        label def apathy 0 "null", modify
        label def apathy 1 " Abulia/apathy", modify
        label values fatigue fatigue
        label def fatigue 0 "null", modify
        label def fatigue 1 "Fatigue", modify
        label values flight_of_ideas ideas
        label def ideas 0 "null", modify
        label def ideas 1 "Flight ideas", modify
        
        frame put *, into(graph)
        frame graph{
            rename * var=
            gen long obsno=_n
            reshape long var, i(obsno) j(which) string
            gen cat= cond(missing(var), "Missing", cond(var==1, "Yes", "No"))
            replace which= proper(which)
            replace which = "Flight of ideas" if regexm(which,"Flight")
            replace which= subinstr(which, "_", " ", .)
            bys which: gen proportion=_N
            bys which cat: replace proportion=_N/proportion
            bys which cat: keep if _n==1
            set scheme s1color
            graph hbar proportion, over(cat) over(which, sort(3)) ytitle("Proportion") ///
            asyvars showyvars leg(off) bargap(10) bar(1, color(green)) ///
            bar(2, color(green*0.6)) bar(3, color(navy))
        }
        frame drop graph
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	59.0 KB
ID:	1716535

        Last edited by Andrew Musau; 08 Jun 2023, 17:06.

        Comment


        • #5
          This is really helpful Andrew, thank you- the colors are great, thank you. However what I need to plot is the proportion of people who answered yes only for each of these variables: anhedonia, fatigue, flight of ideas and apathy and for each of them I would like to categorize by those who answered yes to schizophrenia and schizoaffective. In the actual data, there are three categories (I.e schizophrenia, schizoaffective and one more category) I was provided with two datasets ,in one dataset, each category comes as a binary variable, in another dataset, it’s just categorical variable. Also in the actual dataset, the variables listed above are 9 in total, similar to what I showed in the sample graph.
          Last edited by Mary Atieno; 09 Jun 2023, 01:44.

          Comment


          • #6
            EDITED: Here is some clarification in terms of how I calculate the proportions, but it is unclear whether this is what you want. First, I drop missing responses. Then I calculate the proportion of individuals answering yes for a particular category, i.e., total yes/ total yes and no. This takes the subcategory 1 in the graph. 2 represents the proportion of those who answered yes to the category and yes to schizophrenia in relation to those who answered yes and no to the category. Similarly, 3 represents the proportion of those who answered yes for the category and yes to schizoaffective. Label the subcategories accordingly.


            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input float(anhedonia apathy fatigue flight_of_ideas Schizophrenia Schizoaffective)
            0 0 1 1 0 0
            . 0 . . 0 0
            0 0 . . 0 0
            0 0 . . 0 0
            0 0 . . 0 0
            . 0 . . 0 0
            0 0 . . 0 0
            . 0 . . 0 0
            0 0 . . 1 0
            . 0 . . 0 0
            . 0 . . 0 0
            0 1 1 0 0 0
            0 0 1 1 1 0
            0 0 . 1 1 0
            0 0 1 1 0 0
            0 0 . . 1 0
            0 0 . 1 0 0
            0 0 . 0 0 0
            0 0 . . 0 0
            0 1 . 1 1 0
            0 0 . . 0 0
            0 0 . . 0 0
            0 1 . . 1 0
            0 0 . . 1 0
            0 1 1 0 0 1
            0 0 0 1 1 0
            1 1 1 1 1 0
            . 0 . . 0 0
            0 0 . . 1 0
            . 0 . . 0 0
            0 0 . . 0 0
            . 0 . . 0 0
            0 1 . . 1 0
            0 0 . . 0 0
            . 0 . . 0 0
            0 0 0 1 0 0
            . 0 . . 0 0
            . 0 . . 0 0
            0 1 . . 1 0
            . 0 . . 0 0
            0 0 . . 0 0
            0 1 . . 1 0
            0 1 1 . 0 1
            0 0 . . 0 0
            0 1 . . 1 0
            0 0 . . 0 0
            0 1 1 . 1 0
            . 0 . . 0 0
            0 0 . . 0 0
            0 0 1 1 0 0
            0 1 . . 1 0
            0 0 . . 0 0
            0 0 . . 0 0
            0 1 . 1 1 0
            0 0 1 1 1 0
            . 0 . . 0 0
            . 0 . . 0 0
            0 0 . . 1 0
            . 0 . . 0 0
            0 0 1 1 1 0
            . 0 . . 0 0
            0 0 0 1 1 0
            0 1 1 1 1 0
            0 0 1 1 1 0
            1 0 0 1 0 0
            0 1 . . 1 0
            0 1 . . 0 0
            . 0 . . 0 0
            1 0 0 1 1 0
            0 1 . . 1 0
            0 1 . 0 1 0
            0 1 1 . 1 0
            0 0 0 1 0 0
            0 0 . . 0 0
            0 1 . 0 1 0
            0 1 . . 1 0
            . 0 . . 0 0
            . 0 . . 0 0
            . 0 . . 0 0
            0 1 . . 1 0
            . 0 . . 0 0
            . 0 . . 0 0
            . 0 . . 0 0
            . 0 . . 0 0
            1 0 1 . 0 0
            0 0 . . 0 0
            0 0 . . 0 0
            0 0 . . 1 0
            0 0 . . 0 0
            1 0 1 1 0 0
            0 1 1 1 1 0
            0 0 . . 0 0
            . 0 . . 0 0
            . 0 . . 0 0
            0 0 0 . 1 0
            0 0 . . 0 0
            0 0 1 1 0 0
            . 0 . . 0 0
            0 1 . 1 1 0
            . 0 . . 0 0
            end
            label values anhedonia anhedonia
            label def anhedonia 0 "null", modify
            label def anhedonia 1 "Anhedonia", modify
            label values apathy apathy
            label def apathy 0 "null", modify
            label def apathy 1 " Abulia/apathy", modify
            label values fatigue fatigue
            label def fatigue 0 "null", modify
            label def fatigue 1 "Fatigue", modify
            label values flight_of_ideas ideas
            label def ideas 0 "null", modify
            label def ideas 1 "Flight ideas", modify
            
            frame put *, into(graph)
            frame graph{
                foreach var of varlist anhedonia -flight{
                    gen `var'2=`var'==1 & Schizophrenia==1
                    gen `var'3=`var'==1 & Schizoaffective==1
                }
                rename (anhedonia -flight_of_ideas) (anhedonia1 apathy1 fatigue1 flight_of_ideas1)
                drop Schizophrenia Schizoaffective
                gen long obsno=_n
                reshape long anhedonia apathy fatigue flight_of_ideas, i(obsno) j(which)
                rename (anhedonia apathy fatigue flight_of_ideas) var=
                replace obsno=_n
                reshape long var, i(obsno) j(cat) string
                keep if !missing(var)
                replace cat= proper(cat)
                replace cat = "Flight of ideas" if regexm(cat,"Flight")
                replace cat= subinstr(cat, "_", " ", .)
                bys cat: egen proportion=total(which==1)
                keep if var==1
                bys cat which: replace proportion=_N/proportion
                set scheme s1color
                graph hbar proportion, over(which, lab(labsize(small))) over(cat, sort(1)) ///
                ytitle("Proportion") asyvars showyvars leg(off) bargap(10) ///
                bar(1, color(green)) bar(2, color(green*0.6)) bar(3, color(navy))
            }
            frame drop graph
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	37.7 KB
ID:	1716620

            Last edited by Andrew Musau; 09 Jun 2023, 08:32.

            Comment


            • #7
              This is precisely what I was looking for, thank you very much!

              Comment


              • #8
                There might be a better order psychiatrically for these outcomes than alphabetical!

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  There might be a better order psychiatrically for these outcomes than alphabetical!
                  I have

                  over(cat, sort(1))
                  in #6, so the alphabetical ordering just happens to coincide with the ordered proportions for bar #1. However, some other ordering may yet make sense.

                  Comment


                  • #10
                    Andrew Musau Absolutely.. The comment was directed at Mary Atieno or anyone else competent to advise on subject-matter content.

                    Comment


                    • #11
                      Got it, Nick!

                      Comment


                      • #12
                        Originally posted by Nick Cox View Post
                        There might be a better order psychiatrically for these outcomes than alphabetical!
                        Hello Nick, thank you for the question, for the context in which this will be presented, the categories are arbitrary, i.e none is of more superior interest than the other

                        Comment

                        Working...
                        X