Announcement

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

  • combining boxplot and scatter graph

    Hi

    Using Stata 13, I try to overlay/ combine a scatter graph over a boxplot graph using the command line:
    graph box var1 if var2==0, over(var3) || scatter var1 var3 if var2==1

    Receiving the error message r(198) stating:
    'graph is not a twoway plot type' or 'option | not allowed' depending which graph is first in the command line.

    Is there anyway to combine the two graphs?

    Thank you
    Ruth



  • #2
    I am not clear what you expect to happen there, but consider

    Code:
    sysuse auto
    
    graph7 mpg weight, twoway oneway box xla yla

    Comment


    • #3
      Hi Nick

      thank you so much for your reply. I have attached a link to a site which shows what I am trying to do http://stackoverflow.com/questions/2...oxplot-overlay .

      thank you
      Ruth

      Comment


      • #4
        stripplot (SSC) can do similar plots. See e.g. http://www.statalist.org/forums/foru...updated-on-ssc and search the forum for mentions.

        That post is already almost out of date as revised code and help file for stripplot will be released shortly.

        Comment


        • #5
          Nick, thank you very much for your help, will do.

          Comment


          • #6
            Hi

            I also get the exact same errors using double pipes to join graphs.
            I would also like a boxplot with a dot plot (drawn using the scatter command). It seems as the syntax to join is not correct

            scatter var1 var2 || graph box var1, over(var2)

            var2 i created from 3 variables, (age stratum sex and year), as I would like to see how var1 is distributed in each combination. There are about 1000 obs and I would like to jitter the scattered dots to fill in the width of the boxes. Unfortunately var1 is also discrete, assuming the value of natural numbers, so the stripplot doesn't look good.

            I've seen there exist code to draw a box over an histogram but not what I seek

            Thank you very much

            Comment


            • #7
              Nazzarena: The code you cite is illegal for the reasons already implied earlier in the thread: graph box is quite separate from twoway commands such as scatter and the two cannot be combined (except in the sense of graph combine). The only practical way to get a combination plot is to use twoway to draw the box elements, which is feasible.

              As for stripplot not looking good: I would like to comment, but I see no graph, no data to work with and no code that you used, so I can't advise specifically. There is no intrinsic problem in plotting integer-valued variables and several of the numerous examples in the stripplot help do precisely that.

              Comment


              • #8
                I am struggling with the same problem.
                Click image for larger version

Name:	Box-scatter.png
Views:	1
Size:	423.2 KB
ID:	1545685

                Comment


                • #9
                  I am trying to creat this, with 2 y axis, you have:
                  yaxis 1 with valve calcification as a continues variable
                  x-axis "valve calcification in groups"
                  yaxis 2 is Aortic Valve Area

                  graph twoway (bar ctf_avc valve_calcification_groups, yaxis(1) ytitle("Aortic Valve Calcification", axis(1))) (bar AVA valve_calcification_groups, yaxis (2) ytitle("Aortic Valve Area", axis(2))),xtitle("Valve Calcification in Groups") title("Aortic Valve Calcification and Aortic Valve Area")

                  these are bars with two y axis, but how do I choose a scatter line for one and box plot for the other

                  Comment


                  • #10
                    #8 doesn't look like the same problem to me. You have a curve, a line that may be straight, some point estimates and some confidence intervals or similar.

                    All good for twoway line || line || scatter || rcap

                    Comment


                    • #11
                      With the command above I get the following, which is not what I want Click image for larger version

Name:	AVC_AVA.jpg
Views:	1
Size:	220.3 KB
ID:	1545689

                      Comment


                      • #12
                        Thank you very much Nick ! I got to know that I should combine a boxplot with line, but lemme see

                        Comment


                        • #13
                          How can I use STATA to make a graph like this? #Professor Cox

                          Last edited by Md. Abdur Rouf Sarkar; 13 Aug 2022, 09:29.

                          Comment


                          • #14
                            That is programmable with graph twoway but not trivially. Dot and box plots side by side can be done using stripplot from
                            SSC.

                            Comment

                            Working...
                            X