Announcement

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

  • Boxplot overlay scatter plot

    Dear Statalist users,

    I am trying to create a graph with group on the x-axis and concentration on the y-axis with a scatter plot for each group in a scatter and a box plot overlaying the scatter plots. Previously in older versions of Stata I have used the stripplot command, however, this is no longer available in Stata 18.0.

    Would anyone know a new way to do this in the latest version of Stata? I'm afraid I have no examples to show, but I can show you the scatter plot I would like to overlay the box plot on using the Auto data:
    Code:
    twoway scatter mpg foreign
    I look forward to your responses.

    Annaelle

  • #2
    stripplot is community-contributed and downloadable from SSC. See https://www.statalist.org/forums/for...updated-on-ssc.

    Code:
    ssc install stripplot, replace
    Last edited by Andrew Musau; 11 Oct 2023, 07:20.

    Comment


    • #3
      I am the author of stripplot and confirm that there is no sense in which it’s not available in 18. Either it has not been installed or your adopath does not point to its location on your system.

      Comment


      • #4
        Hi both,

        I am sorry I must have not had it set up properly as it wouldn't install. It has installed now and I am very happy so thank you.

        I have another question, is it possible to code the groups so that they are different colours with this code?

        Code:
        stripplot mpg, over(foreign) vertical box

        Comment


        • #5
          Use the separate() option to get different colour.

          Comment


          • #6
            Hello Nick,

            Thank you for letting me know this separate() code. I have used this but I am having difficulties with specifying the colour I would like each group to be coded by. Currently they come out in different colours but automated ones.

            This is the code I am using:
            Code:
            stripplot NfL, over(disease_grp) vertical box separate(disease_grp)
            The variable NfL is a continuous variable, and I will have 9 disease groups to display with their NfL data scattered with over laying box plots. I already have a colour scheme for each group - is it possible to apply these colours to the groups?

            For example with the auto data:
            Code:
            stripplot mpg, over(foreign) vertical box separate(foreign)

            Comment


            • #7
              Code:
              sysuse auto, clear 
              
              stripplot mpg, over(foreign) vertical box separate(foreign) mc(red blue)
              So, yes, just specify your colours in order. But this may go awry if all 9 groups are not present in all graphs. You'd need extra code to cope with any such problems.

              Comment


              • #8
                Hello Nick,

                Thank you for your help with this, my plot is just how I wanted it to look!

                I am having trouble adding whiskers to the plot. I would like to add whiskers representing the 95% interval of the data - would this be possible?

                When I add the whiskers option to the code it doesn't add the lines, am I missing specific code?

                Code:
                 sysuse auto, clear
                
                stripplot mpg, over(foreign) vertical box separate(foreign) mc(red blue) whiskers(vertical)

                Comment


                • #9
                  stripplot doesn't know that you want whiskers between 5 and 95% points unless you add the pctile(5) option. The whiskers() option serves only to tune the appearance of whiskers asked for separately.

                  Or perhaps you want pctile(2.5). At this moment I am leaving for a meeting and don't have time to check whether that would work.
                  Last edited by Nick Cox; 25 Oct 2023, 06:10.

                  Comment

                  Working...
                  X