Announcement

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

  • Scatter plot with weights and different colours

    Hello,

    I'm trying to make something like a forest plot, with markers weighted by number of observations. I also want my categories in different colours. I can't seem to combine the two: either I can specify different plots with twoway and give them different colours, but each plot is apparently weighted individually so the marker sizes are the same; or I can specify them as one plot, which allows me to use weights, but not different colours.

    Here are the two things I'd like to combine:
    Click image for larger version

Name:	cholest annual change _c2 (2).png
Views:	2
Size:	29.2 KB
ID:	1349378 Click image for larger version

Name:	cholest annual change _c2.png
Views:	2
Size:	29.4 KB
ID:	1349377




    My dataset has one observation per BMI category, with an estimate and a confidence interval for mean change per year.

    This is my code at the moment, with the weighted/uncoloured version commented out:

    Code:
        #delimit ;
            
        twoway    /// CIs
                (rspike ann_lci_`rfvar' ann_uci_`rfvar' bmicat if bmicat == 1
                    , horizontal color($c1 )) 
                (rspike ann_lci_`rfvar' ann_uci_`rfvar' bmicat if bmicat == 2
                    , horizontal color($c2 )) 
                (rspike ann_lci_`rfvar' ann_uci_`rfvar' bmicat if bmicat == 3
                    , horizontal color($c3 )) 
                /// markers (colour)
                (scatter bmicat ann_est_`rfvar' if bmicat == 1 [aweight=respbmi] 
                    , color($c1 ) msymbol(square) msize(medlarge)) 
                (scatter bmicat ann_est_`rfvar' if bmicat == 2 [aweight=respbmi] 
                    , color($c2 ) msymbol(square) msize(medlarge)) 
                (scatter bmicat ann_est_`rfvar' if bmicat == 3 [aweight=respbmi] 
                    , color($c3 ) msymbol(square) msize(medlarge))
                /* /// markers (weights)
                (scatter bmicat ann_est_`rfvar' [fweight = resp]
                    , msymbol(square) msize(medlarge) mcolor(gs2))
                */
                /// options            
                , xtitle("Annual change") xline(0) xmtick(none) 
                ytitle("") yscale(range(-1 5) lcolor(none) reverse) ymtick(none)
                ylabel(1 "< 25" 2 "25-29" 3 "30+"
                    , angle(horizontal) notick nogrid)
                title("Annual change in `rfname' by BMI category") 
                legend(off) scheme(s1mono) plotregion(lcolor(none)) 
                name(`rfvar'_annual_c2, replace)
                ;
    
        #delimit cr


    I explored adding my three data points as different variables into the same scatter plot, but as you can only specify the x variable once, I could only orient my plot vertically. I looked for a way to transpose the x and y axis, but there doesn't seem to be one.

    Any advice?
    Attached Files

  • #2
    I would look into the -coefplot- package, it is very customizable.

    Check this page: http://repec.sowi.unibe.ch/files/wp1...3-coefplot.pdf

    Kr, Inge

    Comment


    • #3
      FAQ 12 with emphasis on 12.2: You are unlikely to get a direct solution if you do not show us a sample of your data that created the graphs.

      Comment

      Working...
      X