Announcement

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

  • Extending plot by combining graphs

    I am looking to split out my graph into one which ranges from 0 to 100 percent and another that provides information showing outliers. In this case Vermont is suppressing the remaining values when plotting all the data together as one. Nick Cox has a post (https://www.stata.com/support/faqs/g.../scale-breaks/) whereby he combines two plots with a gap between them to account for the outlier data. I am looking to perform something similar using a dumbbell chart. Below is an example of the code I have now, and data. I have tried to filter the data by value to create the two graphs however I do not want the line of the outlier values to be removed, I want them to display to 100 and then cut off to be displayed in the second graph. If possible, I would also like to display two groups per state (e.g., cc_pct and cc_85_pct for each state in the same graph).

    Thank you in advance for your time.

    Adam

    Code:
    twoway (rspike solar_pct cc_pct srno if cc_pct, horizontal lcolor("`r(p6)'*0.4") xscale(range(-10 100))) ///
    (scatter srno solar_pct, mcolor("63 86 97") mlabel(solar_label) mlabp(9)) ///
    (scatter srno cc_pct if cc_pct < 100, mcolor("0 88 141") mlabel(cc_label)), ylabel(3(3)45, valuelabel angle(horizontal) labsize(2)) ///
    legend(order(2 "Current" 3 "Potential") pos(11) row(1) size(2)) ytitle("") title("{bf}A. Climate Crisis", pos(11) size(2.75)) ///
    subtitle("FPV contribution to share of solar generation", pos(11) size(2)) scheme(white_tableau) name(cc_plot, replace) ///

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3 state_abbr float(solar_pct cc_pct cc_85_pct srno) str6 solar_label str8 cc_label str6 cc_85_label
    "CT "  .9588399  9.497645  4.512996  3 "0.96%"  "9.50%"    "4.51%"
    "DC "  13.88444  24.05364  24.05364  6 "13.88%" "24.05%"   "24.05%"
    "DE "  1.203345  17.77997  12.75813  9 "1.20%"  "17.78%"   "12.76%"
    "MA "   9.19894 68.723465  31.05716 12 "9.20%"  "68.72%"   "31.06%"
    "MD "  1.921227 10.756673  4.615096 15 "1.92%"  "10.76%"   "4.62%"
    "ME"   3.382087  187.0453 14.964627 18 "3.38%"  "187.05%"  "14.96%"
    "NH"  .02082668  56.97899  7.504166 21 "0.02%"  "56.98%"   "7.50%"
    "NJ"  2.3339684  10.93172  6.637424 24 "2.33%"  "10.93%"   "6.64%"
    "NY " 1.4260793  53.92334  7.350178 27 "1.43%"  "53.92%"   "7.35%"
    "PA"  .09923972  5.095839 1.7630134 30 "0.10%"  "5.10%"    "1.76%"
    "RI"   4.624532 16.988964 11.234145 33 "4.62%"  "16.99%"   "11.23%"
    "VA"   5.169766 27.386595 11.135032 36 "5.17%"  "27.39%"   "11.14%"
    "VT "  9.255512 1141.1605  46.83222 39 "9.26%"  "1141.16%" "46.83%"
    "WV "         0 4.1546817 1.4292475 42 "0.00%"  "4.15%"    "1.43%"
    "NE"   1.700989 27.352945  6.165952 45 "1.70%"  "27.35%"   "6.17%"
    end
    label values srno srno
    label def srno 3 "CT", modify
    label def srno 6 "DC", modify
    label def srno 9 "DE", modify
    label def srno 12 "MA", modify
    label def srno 15 "MD", modify
    label def srno 18 "ME", modify
    label def srno 21 "NH", modify
    label def srno 24 "NJ", modify
    label def srno 27 "NY", modify
    label def srno 30 "PA", modify
    label def srno 33 "RI", modify
    label def srno 36 "VA", modify
    label def srno 39 "VT", modify
    label def srno 42 "WV", modify
    label def srno 45 "NE", modify

  • #2
    Here is one way:

    Code:
    expand 2 , gen(tag)
    replace srno  = srno - .5 if tag == 1
    replace srno  = srno + .5 if tag == 0
    expand 2 if cc_pct > 100 & tag ==1 ,gen(tag2)
    
    replace cc_pct = 100 if tag2 == 0 & cc_pct > 100
    
    
    twoway rspike solar_pct cc_pct srno if tag == 0, horizontal   lc(black) xscale(range(-10 100)) ///
        || rspike solar_pct cc_85_pct srno if tag == 1, horizontal /// 
        || scatter srno solar_pct if tag == 0 , mcolor("63 86 97") mlabel(solar_label) mlabp(9)  ///
        || scatter srno cc_pct  if cc_pct< 100 & tag == 0 , mcolor("0 88 141") mlabel(cc_label) ///
        || scatter srno cc_85_pct  if  tag == 1 , mcolor("0 88 141") mlabel(cc_85_label) ///
        || , ylabel(3(3)46, valuelabel angle(horizontal) labsize(2)) ///
        legend(order(1 "CC" 2 "CC 85" 3 "Current" 4 "Potential") pos(11) row(1) size(2)) /// 
        ytitle("") title("{bf}A. Climate Crisis", pos(11) size(2.75)) ///
        subtitle("FPV contribution to share of solar generation", pos(11) size(2)) /// 
        scheme(white_tableau) name(gr1,replace)
    
    replace solar_pct = 180 if tag2 == 1
    replace solar_pct  = . if tag2 == 0
    replace cc_pct  = . if tag2 == 0
    replace srno = srno  +1 if tag2 ==1
    
    twoway rspike solar_pct cc_pct srno if tag == 0 & tag2 == 0 , horizontal lc(white) ylabel(3(3)46)  /// 
        || rspike solar_pct cc_pct srno if tag == 1 & tag2 == 1, horizontal lcolor(black) /// 
        || scatter srno cc_pct  if  tag2 == 1 , mcolor("0 88 141") mlabel(cc_label) /// 
        yscale(off) xlabel(180 1150) xtitle("")  fxsize(20) /// 
        legend( order(1 " "2 " ")  symysize(*.0)  symxsize(*.0)  pos(11) row(1) size(2) color(white)) /// 
        ytitle("") title("{bf}A. Climate Crisis", pos(11) size(2.75) color(white) ) ///
        subtitle("FPV contribution to share of solar generation", pos(11) size(2) color(white)) /// 
         name(gr2,replace)     scheme(white_tableau) 
    
    graph combine gr1 gr2, row(1) ycommon imargin(0 5 0 0)
    Click image for larger version

Name:	Graph1.png
Views:	1
Size:	189.2 KB
ID:	1738382

    Comment


    • #3
      This works well for me, thank you for the guidance.

      Comment

      Working...
      X