Announcement

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

  • #16
    Originally posted by Ben Jann View Post
    I believe the addplot() option really only works well with plots that do not contain subgraphs. This is a limitation I cannot change, I'm afraid. You could, however, apply the addplot command, with which you can address individual subgraphs (see the help file).
    Cool, you have made it possible with the new release. I have tested it and it works.

    Comment


    • #17
      As Marc noticed, I fixed the issue with addplot() in combination with by(). violinplot now makes sure that the correct observations are available to addplot() within each subgraph. Type

      Code:
      . ssc install violinplot, replace
      to obtain the update.

      Some further additions:
      • it is now possible to display the IQR box as a shaded area or as lines across the density, rather than as a bar; likewise, median and mean can now be displayed as lines (see example below)
      • the statistics used for box, median and mean can now be customized; for example, type box(stat(p10 p90)) to use the 10% and 90% quantiles for the box, rather than the default 25% and 75% quantiles
      • it is now possible to sort results across over groups; see subpption sort() in over()
      Example: Box as shading, median as line

      Code:
      . sysuse nlsw88
      . violinplot wage if grade>10, over(grade) vertical box(type(fill)) median(type(line))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	172.6 KB
ID:	1689164

      Comment


      • #18
        A further update to violinplot is available from SSC. The install the update type

        Code:
        . ssc install violinplot, replase
        . ssc install dstat, replace
        . ssc install moremata, replace
        (A small change was necessary in dstat and moremata, on which violinplot depends; this is why these packages also need to be updated.)

        The most important change is that violinplot now has a split() option to create half violins. Example:

        Code:
        . sysuse nlsw88
        . violinplot wage ttl_exp tenure, pdf(ll(0)) split(union) key(fill)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	125.4 KB
ID:	1690851


        ben

        Comment


        • #19
          Yet more features have been added to violinplot. To install the new version, type

          Code:
          ssc install violinplot, replace
          For a list of changes see https://github.com/benjann/violinplot. For example, it is now possible to print only half of a violin (options left and right) and it is also possible to include the data in the plot, see option rag(). Here are some examples:

          Code:
          sysuse nlsw88
          violinplot wage, left rag(offset(-.005) mlcolor(%20)) dscale(.)
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	92.9 KB
ID:	1691909

          Code:
          sysuse auto
          violinplot price, over(foreign) vertical rag(spread(5) msymbol(o) mcolor(maroon%50) mlcolor(%0))
          Click image for larger version

Name:	Graph2.png
Views:	1
Size:	144.7 KB
ID:	1691910

          Comment


          • #20
            Hi Ben! Thanks a lot for all the information and work on vioplot in STATA. I have been trying to use it myself and have a dataset with variables consumption (float), paddy (float, with values 0 and 1) and round (float) with values ranging from 1-19. But somehow the over option does not seem to work with either paddy or round. The code I am trying to use:

            Code:
            violinplot total_consumption_per_day, pdf(ll(0)) noline fill(fcolor(%50) lcolor(%100)) over(paddy)
            Can you please tell me what the problem could be here?

            Comment


            • #21
              Originally posted by Kuber Bathla View Post
              Hi Ben! Thanks a lot for all the information and work on vioplot in STATA. I have been trying to use it myself and have a dataset with variables consumption (float), paddy (float, with values 0 and 1) and round (float) with values ranging from 1-19. But somehow the over option does not seem to work with either paddy or round. The code I am trying to use:

              Code:
              violinplot total_consumption_per_day, pdf(ll(0)) noline fill(fcolor(%50) lcolor(%100)) over(paddy)
              Can you please tell me what the problem could be here?
              For context, I am using STATA 15

              Comment


              • #22
                Need more info. What do you mean by "does not seem to work"? Is there an error message? If not, in what way is the result different from what you expected?

                Comment


                • #23
                  It simply says "invalid syntax". I think it has something to do with the over() function, since the command works fine if I remove it. If I use the following code:

                  Code:
                  violinplot total_consumption_per_day, pdf(ll(0)) noline fill(fcolor(%50) lcolor(%100))
                  I get the following graph:
                  Click image for larger version

Name:	Graph.png
Views:	1
Size:	47.0 KB
ID:	1740957


                  But ideally I want the plot to have two categories, just like you have done with the union variable in your example. Also, I tried using the sample dataset nlsw88, but even then I get the same error message if I try to use the over() function. Works fine if I don't use it. Any idea what could be the issue? Thanks for your time.

                  Comment


                  • #24
                    Code:
                    set trace on 
                    set tracedepth 1
                    before running the command to see where it fails. You may need to bump up the trace depth.

                    Detail: over() is an option. not a function.

                    Quite different:
                    What underlies the data here? Are there lots of zeros? It would be interesting (to me) to get a copy or a tabulation of the data to be able to compare with say a quantile plot.

                    Comment


                    • #25
                      Hi! Need help with plotting violin plots...
                      I have been modifying this command:

                      violinplot Difference_CH2tau1, split(MMRStatus) noline fill(fintensity(30)) mean(type(m) m(o) mc(white)) box(type(bar)) med(type(l)) rag(spread(30) msymbol(o) mcolor(%60) mlc(%0))

                      To obtain the following plot...
                      Click image for larger version

Name:	Screenshot 2024-01-24 at 18.07.27.png
Views:	2
Size:	384.9 KB
ID:	1741031
                      But when I try to rescale the density function, the box plot and the density is separated, like this:
                      Click image for larger version

Name:	Screenshot 2024-01-24 at 17.58.55.png
Views:	1
Size:	379.9 KB
ID:	1741032
                      Is there any way to rescale the density plot in order to obtain more uniform plots?

                      Thank you in advance for your help.

                      By the way, the new violin plot command is awesome!
                      Attached Files

                      Comment


                      • #26
                        #25

                        Please show the results of

                        Code:
                        dataex  Difference_CH2tau1  MMRStatus)
                        to allow people to experiment. https://www.statalist.org/forums/help#stata explains why and how.

                        Comment


                        • #27
                          My apologises, I have been without internet. Here are the data...

                          * Example generated by -dataex-. For more info, type help dataex
                          clear
                          input float Difference_CH2tau1 long MMRStatus
                          -.16197658 2
                          . .
                          -.007025041 2
                          -.10418536 1
                          .27124527 2
                          .1481722 2
                          . .
                          . .
                          -.07709967 1
                          . .
                          -.06960077 1
                          -.08417155 1
                          -.02936337 2
                          . .
                          -.18138254 1
                          .0463042 2
                          . .
                          -.071427256 1
                          -.1559932 2
                          . .
                          -.02504033 2
                          -.0346483 2
                          -.010934993 2
                          .07938742 2
                          .06219372 2
                          -.03885114 2
                          .026179945 2
                          .035119455 2
                          -.12766866 2
                          . .
                          .00698373 2
                          .02014844 2
                          -.04258387 2
                          . .
                          -.22304997 1
                          -.005390899 2
                          -.01830321 2
                          .02029349 2
                          -.014603627 2
                          . .
                          . .
                          .008351903 .
                          .0799145 2
                          -.0823106 2
                          .03225925 2
                          -.1486648 2
                          -.02678861 2
                          -.003597375 2
                          .07531597 2
                          -.018329207 2
                          . .
                          -.13695839 2
                          .00992492 2
                          .1639622 2
                          . 2
                          -.13790636 2
                          . .
                          -.047202 2
                          -.07472075 2
                          -.1835154 2
                          -.13675424 2
                          .034751717 2
                          .15841062 2
                          end
                          label values MMRStatus MMRStatus
                          label def MMRStatus 1 "Deficient", modify
                          label def MMRStatus 2 "Proficient", modify
                          [/CODE]

                          Comment


                          • #28
                            Thanks for the data example. Questions about violinplot I will happily leave to the guru, Ben Jann.

                            Just curious on what might work well too. I used stripplot from SSC.

                            Code:
                            stripplot Diff, over(MMR) height(0.6) centre cumul cumprob vertical box(barw(0.05)) pctile(0) boffset(-0.4) refline xla(, noticks)
                            I find a direct quantile or cumulative display easier to read than the jittering. And a density function estimate from 7 data points is a bit of a stretch. The longer lines show means.

                            The key points are banal.

                            Experienced people just won't agree where taste and judgment are needed.

                            Which design suits your data, your purposes and your intended readership? That is your call.
                            Click image for larger version

Name:	notaviolin.png
Views:	1
Size:	42.5 KB
ID:	1741439

                            Comment


                            • #29
                              Hi Nick and Ben. Sorry for not being able to respond. Nick Cox, I tried what you suggested, and the code seems to stop here:

                              Code:
                              - if `pstyles'!=1 {
                              = if 1!=1 {
                                numlist "1/`=min(`pstyles', 15)'"
                                local pstyles `r(numlist)'
                                }
                              - }
                              - forv p = 1/`k_`PID'' {
                              = forv p = 1/. {
                              invalid syntax
                              But I am not sure how to interpret this. Also attaching the log file in case you wish to check the entire output. Will appreciate any help.

                              Also, here is an example of my dataset. The values in total_consumption_per_day represent mean consumption in terms of hours for agricultural pumpsets, measured using hour meter devices.

                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input float(total_consumption_per_day paddy)
                               125.25137 0
                                       . 0
                                    18.9 0
                                       0 0
                               37.449398 0
                                76.77143 0
                               19.937143 0
                               16.236254 0
                                41.04235 0
                                82.77869 0
                               141.02322 0
                                4.226332 0
                               131.72212 0
                                       0 0
                               37.910713 0
                               19.958385 0
                               19.415533 0
                               14.906833 0
                                18.10388 0
                                49.62073 0
                               1.7585015 0
                                9.646296 0
                               154.54443 0
                                98.43455 0
                                 40.5741 0
                                47.96319 0
                                30.27508 0
                                51.62422 0
                                7.257558 0
                                177.9645 0
                                 85.9939 0
                                30.81851 0
                                       . 0
                                  140.72 0
                                2.504587 0
                                       0 0
                               10.916012 0
                                       0 0
                               117.22666 0
                                3.136517 0
                               3.0946524 0
                               140.09811 0
                               1.6666666 0
                                       0 0
                                5.925696 0
                                85.22687 0
                                62.15059 0
                                4.914019 0
                                5.312694 0
                                7.570588 0
                              .003680982 0
                                177.8084 0
                                44.24389 0
                                       0 0
                                       0 0
                               18.867924 0
                               111.47853 0
                                50.17107 0
                                .9648902 0
                                59.81667 0
                                       0 0
                               133.50095 0
                               1.3446254 0
                                59.55138 0
                                84.46487 0
                                41.34985 0
                                       0 0
                                9.152866 0
                               4.6560745 0
                                44.26038 0
                                2.467826 0
                                43.30384 0
                                28.12215 0
                                24.49059 0
                               157.89146 0
                               120.19514 0
                               25.969326 0
                                24.63889 0
                                21.08647 0
                               2.3226993 0
                                5.003704 0
                               126.68902 0
                                       0 0
                               102.83743 0
                               111.19701 0
                               123.88777 0
                                13.34277 0
                                     540 0
                                       0 0
                                7.898508 0
                                48.08802 0
                                       0 0
                                8.163935 0
                                89.50286 0
                               4.3003097 0
                                37.20743 0
                                   10.95 0
                                19.57612 0
                               2.0337424 0
                                9.210366 0
                              end
                              Attached Files

                              Comment


                              • #30
                                #29 is really for Ben Jann.

                                Comment

                                Working...
                                X