Announcement

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

  • Is it possible to graph multiple variables in a stripplot?

    Hi,

    I have a question regarding ssc stripplot.

    Is it possible to graph multiple variables in a stripplot and to further separate the variables by group. Using the auto data set:

    Code:
     sysuse auto
    stripplot trunk weight length, over (foreign)
    With my real data set the variables would all have the same units. I understand here that trunk, weight, and length in fact have different units. The goal is for one graph with each of the 3 variables, but separated side by side for each categorization of foreign.

    Thanks!

  • #2
    Code:
    stripplot trunk weight length, sep(foreign) vertical
    1.png


    Code:
    stripplot trunk, over(foreign) vertical name(n1, replace) 
    stripplot weight, over(foreign) vertical name(n2, replace)
    stripplot length, over(foreign) vertical name(n3, replace)
    
    * combine them into one graph
    
    graph combine n1 n2 n3, row(1)
    2.png

    I'm not sure if I understand exactly what you're looking for. Are you by any chance looking for one of these graphs? If not, could you please show how you would like your graph to look?

    Comment


    • #3
      Presumably Jay Gold tried the syntax in #1 and got an error message: over() is not supported with more than 1 variable.

      Code:
      sysuse auto
      stripplot trunk weight length, over(foreign)
      In addition to the suggestions of Guest, you could progress with a different data layout:

      Code:
      webuse citytemp, clear
      
      label save region using region.do, replace
      
      stack heatdd region cooldd region, into(dd region) clear
      label def _stack 1 Heating 2 Cooling  
      label val _stack _stack  
      
      do region
      label val region region
      
      stripplot dd, over(region) separate(region) by(_stack, note("") legend(off)) ///
      vertical stack width(250) centre xtitle("") ytitle(Heating and cooling degree days (days {&degree}F))
      Click image for larger version

Name:	stripplot_group.png
Views:	1
Size:	74.3 KB
ID:	1767348

      Last edited by sladmin; 19 Nov 2024, 08:37. Reason: anonymize original poster

      Comment


      • #4
        Hi Guest,

        Thanks for responding to help! The second set of graphs is close to what I am looking for. I would want to combine it all into one graph rather than 3 separate panels. Again, I know that trunk weight and length have different units, but just using this as a sample data set. My variables that are equivalent to trunk, weight, and length have the same units.

        Also, is it possible to have domestic and foreign in separate colors?
        Last edited by sladmin; 19 Nov 2024, 08:38. Reason: anonymize original poster

        Comment


        • #5
          Thank you Dr. Cox! That is close to what I am looking for. Ideally, it would be one graph and the dd variable is displayed with heating and cooling right next to each other for each region. In other words, the dd variable for region NE, N Cntrl, South, West is plotted side by side for heating and cooling rather than in two separate panels.

          Comment


          • #6
            You asked in #1 for distinct groups of a variable to be side by side. Now it's variables!

            Code:
            webuse citytemp, clear 
            
            stripplot heatdd cooldd, by(region, note("") legend(off)) ///
            vertical stack width(250) centre xtitle("") ytitle(Heating and cooling degree days (days {&degree}F))

            Comment


            • #7
              Thank you Dr. Cox. That is very close in #6. Is it possible to instead have all the data in one graph instead of 4 panels?

              Comment


              • #8
                See

                Code:
                help by option
                for standard suboptions such as row(1) compact.

                Comment


                • #9
                  by() still limits the graph to multiple panels, even if the options allow the panels to get close to each other like with row(). I am trying to the graph in #3 but with the NE heating next to the NE cooling which is then next to N Cntrl heating next to the NCntrl cooling and so on.

                  Comment


                  • #10
                    Actually Nick is writter of stripplot and he has given good guide above. Just resort to his another command named of separate. Use auto.dta to give an example.
                    Code:
                    sysuse auto
                    separate trunk, by(foreign)
                    separate weight, by(foreign)
                    separate length, by(foreign)
                    stripplot trunk0 trunk1 weight0 weight1 length0 length1, separate(foreign) xtitle("")
                    And as a matter of fact the citytemp.dta is more suitable to take as an example. Just try:
                    Code:
                    sysuse citytemp
                    separate tempjan, by(region)
                    separate tempjuly, by(region)
                    stripplot tempjan1 tempjuly1 tempjan2 tempjuly2 tempjan3 tempjuly3 tempjan4 tempjuly4, separate(region) xtitle("")
                    stripplot tempjan1 tempjuly1 tempjan2 tempjuly2 tempjan3 tempjuly3 tempjan4 tempjuly4, separate(region) stack xtitle("")
                    Click image for larger version

Name:	Graph.png
Views:	1
Size:	229.6 KB
ID:	1767377

                    Comment


                    • #11
                      #9 Jay Gold

                      by() still limits the graph to multiple panels, even if the options allow the panels to get close to each other like with row(). I am trying to the graph in #3 but with the NE heating next to the NE cooling which is then next to N Cntrl heating next to the NCntrl cooling and so on.
                      That seems a distinction without a real difference to me. Here is the graph suggested, which does what you ask. If the objection is to the lines bounding each panel, that is a matter of taste.

                      Code:
                      webuse citytemp, clear
                      
                      stripplot heatdd cooldd, by(region, row(1) compact note("") legend(off)) ///
                      vertical stack width(250) centre xtitle("") ytitle(Heating and cooling degree days (days {&degree}F))
                      Click image for larger version

Name:	stripplot_group2.png
Views:	1
Size:	81.4 KB
ID:	1767390



                      #10 Chen Samulsion Thanks for the mention of separate. I did use separate for a trial answer but decided not to post it, on the grounds that using by() gets you to a very similar place with less effort.

                      Comment


                      • #12
                        Thank you Dr. Cox and Chen! Both are fantastic solutions. Grateful for your help.

                        Is it possible to have the data in a different, preferably a user designated color, for the two separate groups heatdd and coldd?

                        Comment


                        • #13
                          With my version, only one colour is allowed.

                          Comment

                          Working...
                          X