Announcement

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

  • #16
    Yet another update to violinplot is now available from SSC. To install the update, type:

    Code:
    ssc install violinplot, replace
    A matrix containing the results of the box plots is now returned in r(); specify option table to also display the matrix in the results window. Example:

    Code:
    . sysuse sp500
    (S&P 500)
    
    . gen condition = ceil(_n/62)
    
    . violinplot open high low close, over(condition) vertical nostack ///
    >     noline nofill key(box) table
    
                1: condition = 1
                2: condition = 2
                3: condition = 3
                4: condition = 4
    
    ------------------------------------------------------------------------------------------
                 |         N       mean     median        p25        p75    whisk_l    whisk_u
    -------------+----------------------------------------------------------------------------
    1            |                                                                            
            open |        62   1275.915   1299.575    1234.18     1341.1    1117.58    1373.73
            high |        62   1285.768    1312.74    1241.36    1350.32    1124.27    1383.37
             low |        62   1260.876   1277.365     1214.5    1329.14    1081.19    1364.66
           close |        62   1273.329   1297.105    1233.42    1340.89    1117.58    1373.73
    -------------+----------------------------------------------------------------------------
    2            |                                                                            
            open |        62   1233.399    1248.33    1212.58    1266.61    1137.59    1312.83
            high |        62   1243.792    1255.58    1225.61     1269.3    1169.51    1315.93
             low |        62   1222.752   1235.135    1207.38    1254.56    1137.51    1306.89
           close |        62    1234.41    1248.33    1214.36    1266.44    1137.59    1312.83
    -------------+----------------------------------------------------------------------------
    3            |                                                                            
            open |        62   1154.159   1182.545    1131.74    1205.82    1032.74    1236.71
            high |        62   1162.049   1188.685    1135.52    1214.44    1018.92    1239.78
             low |        62   1142.005   1170.415    1114.86    1196.14     998.24    1229.43
           close |        62   1151.338    1181.59    1129.03    1204.52     1016.1    1236.72
    -------------+----------------------------------------------------------------------------
    4            |                                                                            
            open |        62   1116.062     1121.7     1085.2    1142.66    1051.33    1170.35
            high |        62   1124.567   1137.185    1097.43    1150.89    1063.37    1173.62
             low |        62   1107.705    1118.09    1076.57     1135.9    1041.48    1164.43
           close |        62    1117.64   1125.805     1087.2    1142.92    1056.75    1170.35
    ------------------------------------------------------------------------------------------

    Comment


    • #17
      Hi, I did some further work on violinplot so that it can be used more easily to draw boxplots (type ssc install violinplot, replace). New option nodensity suppresses the density estimate and changes several other settings so that the result looks like a typical box plot. Here's an example:

      Code:
      . sysuse sp500
      (S&P 500)
      
      . gen condition = ceil(_n/62)
      
      . // violin plot
      . violinplot open high low close, over(condition) nostack
      Click image for larger version

Name:	Graph1.png
Views:	1
Size:	57.3 KB
ID:	1777466

      Code:
      . // box plot
      . violinplot open high low close, over(condition) nostack nodensity
      Click image for larger version

Name:	Graph2.png
Views:	1
Size:	29.6 KB
ID:	1777467


      Code:
      . // box plot including outside values
      . violinplot open high low close, over(condition) nostack nodensity outsides
      Click image for larger version

Name:	Graph3.png
Views:	1
Size:	33.2 KB
ID:	1777468

      There have also been various other changes/additions (some of which slightly affect the default behavior), see the list of changes at github.com/benjann/violinplot.
      ben

      Comment


      • #18
        Dear Ben Jann, thanks for the update. I notice that the width of box is changed in this new version. It is more broader than box drawed by older version, and more like a Stata's official box plot. My personal preference is I like the original width better than width of new version. My second point is why not write a new box plot command, like yours -robbox-, without amending -violinplot-. I think some people will not think about graphing box plot under the name of violin plot. And lastly, I'm excited to see that it becomes more efficient without computing density estimate.

        Originally posted by Ben Jann View Post
        Note that using violinplot to draw boxplots is computationally inefficient; the main purpose of violinplot is to draw density curves and the densities will always be estimated, even if their display is suppressed by noline nofill.

        Comment


        • #19
          Hi Chen, to get the other type of box, add option box(type(spike)):

          Code:
          . sysuse sp500
          (S&P 500)
          
          . gen condition = ceil(_n/62)
          
          . violinplot open high low close, over(condition) nostack nodensity box(type(spike))
          Click image for larger version

Name:	Graph1.png
Views:	1
Size:	27.7 KB
ID:	1777486

          Or use noline and nofill rather than nodensity:

          Code:
          . violinplot open high low close, over(condition) nostack noline nofill vertical
          (same graph as above)

          My second point is why not write a new box plot command, like yours -robbox-, without amending -violinplot-. I think some people will not think about graphing box plot under the name of violin plot.
          Yeah, people interested in box plots will likely not consider violinplot. Implementing a new boxplot command as a wrapper for violinplot would just take a few lines of code.

          Comment

          Working...
          X