Announcement

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

  • New but different violinplot by Ben Jann

    Dear Stata users,
    I found a new violin plot package called -violinplot- wrote by Ben Jann. It gives us a new choice of detecting variable distribution. However, this new -violinplot- command seems quite different from older ones, for example, -violin- (by Thomas J. Steichen) or -vioplot- (by Nicholas Winter and Austin Nichols). Below I gives an example, and could someone tell me what caused this difference. Thank you.

    Code:
    sysuse citytemp
    vioplot heatdd cooldd, name(g1)
    violinplot heatdd cooldd, vertical fill name(g2)
    graph combine g1 g2, ycommon
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	78.3 KB
ID:	1695241

  • #2
    And what am I interested in is how to get a similar violin plot like the one in left panel in #1 using -violinplot-?

    Comment


    • #3
      Dear Chen,

      Together with violinplot another package, written by Ben Jann, will be installed on your system: dstat.
      It is explained in the section Estimation ot the help file of violinplot, how dstat is used:
      pdfopts(options) provides density estimation options to be passed through to dstat; see density_options in help dstat. The same options will be applied used for all results.

      Thus, we can also get your result in #1 by calling the default of pdfopts(options), like:
      Code:
      * dstat default
      violinplot heatdd cooldd, vertical fill pdfopts(bw(dpi)) name(dpi, replace)
      graph combine g1 dpi, ycommon name(dpi, replace)
      * dstat default more explicit
      violinplot heatdd cooldd, vertical fill pdfopts(bw(dpi(2))) name(dpi2, replace)
      graph combine g1 dpi2, ycommon name(dpi2, replace)
      To get a result using
      violinplot, similar to that of vioplot, we have to explore the density_options of dstat, which controls the density estimation, like:
      Code:
      * dstat normal
      violinplot heatdd cooldd, vertical fill pdfopts(bw(n)) name(norm, replace)
      graph combine g1 norm, ycommon name(normal, replace)
      Which results in:
      Click image for larger version

Name:	Example_violinplot_citytemp_normal.png
Views:	1
Size:	50.5 KB
ID:	1695255


      (I did not put further effort into adjusting options for the plot as such to also replicate the layout of the plotregion and the position of the violins.)

      Both
      violinplot and dstat have a lot to offer to inspect your data and how distributions compare between groups.

      You should also have a look at two other user contributed packages when you are interested in this subject:
      Code:
      ssc install joyplot , replace // By Asjad Naqvi
      h joyplot
      which joyplot
      
      ssc install joy_plot , replace // By Fernando Rios-Avila
      h joy_plot 
      which joy_plot
      http://publicationslist.org/eric.melse

      Comment


      • #4
        Dear ericmelse thank you so much for your detailed instructions and further guide to dstat & joy plot. You really help me a lot!

        Comment

        Working...
        X