Announcement

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

  • Question on boxplot and scatter plot

    Hello everyone,

    I have the following questions on graphs, the solutions to which may be very simple.

    1. Boxplot: How can I add a label on a yline in the graph region? For example, the yline is 1 and I want a label next to the line saying "Ideal value". Similarly, I have two other ylines and want labels for those as well. I tried several commands but posting the most recent one:
    Code:
    graph box Ratio, over(desc) ///
        title("Figure: EI and EER", size(medium)) ///
        ytitle ("EI:EER", size(small) margin(medium)) ///
        box(1,  color(gs4)) marker(1, mcolor(gs4) msize(small)) ///
        intensity(75) lintensity(100) graphregion(color(white)) ///
        scheme(s2color) legend(order( 1 "Butte" 2 "Torun")) ///
        yline(1) ylab("Ideal value") ///
        yline(0.79)  ylab("Mean lower cut-off") ///
        yline(1.21) ylab("Mean upper cut-off")
    Also, how can I add a title for the x axis? Logically, because ytitle is for y axis, I tried xtitle and it does not work.


    2. Scatter plot: Is it possible to make more than 2 scatter plots in one twoway scatter plot? The variables are continuous (energy intake and energy expenditure), which I want to plot based on a categorical variable (with 3 categories: under, normal and over). The codes for the first scatter plot is:
    Code:
    twoway (scatter meanEI EER if report_BC1_1sd==0, ///
        xtitle(Energy requirement) ytitle(Energy Intake) title(Figure: Scatter of EI and EER, size(medsmall)) ///
        jitter(10) msize(small) color(gs10)) ///
        (scatter meanEI EER if report_BC1_1sd==1, jitter(10) msize(small) color(gs4)) , scheme(test3) ///
        legend(order( 0 "normal" 1 "under")) ///
        graphregion(color(white))
    2nd scatter:
    Code:
    twoway (scatter meanEI EER if report_BC1_1sd==0, ///
        xtitle(Energy requirement) ytitle(Energy Intake) title(Figure: Scatter of EI and EER, size(medsmall)) ///
        jitter(10) msize(small) color(gs10)) ///
        (scatter meanEI EER if report_BC1_1sd==2, jitter(10) msize(small) color(gs4)) , scheme(test3) ///
        legend(order( 0 "normal" 2"over")) ///
        graphregion(color(white))
    So, how can I have both the scatter plots into one? Is combining the scatter the only option (using graph combine)?
    Is it also possible to have a lfit lines for the scatter plots?

  • #2
    Two techniques are helpful in the forum for graphics questions:

    1. Use reproducible examples, as always.

    2. Show graphs as they are what the question is about.

    This may help with your boxplot questions:

    Code:
     
    sysuse auto
    graph box mpg, over(foreign) b1title(some title on x axis) yline(21) text(22 50 "21 mpg isn't special")


    .
    Click image for larger version

Name:	boxplot_stuff.png
Views:	1
Size:	9.9 KB
ID:	1298096


    On multiple scatter plots, see e.g. http://www.statalist.org/forums/foru...lable-from-ssc
    and other threads mentioning sepscatter (SSC) and the references therein.

    Comment


    • #3
      On the scatterplots:

      Your first command generates two scatterplots in one graph (report_BC1_1sd==0 and 1). So does the second command (report_BC1_1sd==0 and 2). Now I reorganize your first command to make the structure more transparent. The first two lines specify two scatterplots in the same plot area. The third line is the comma separating the plot specifications from the graph options. The rest is graph options.
      Code:
      twoway (scatter meanEI EER if report_BC1_1sd==0, jitter(10) msize(small) color(gs10)) ///
          (scatter meanEI EER if report_BC1_1sd==1, jitter(10) msize(small) color(gs4)) ///
       , ///
       xtitle(Energy requirement) ytitle(Energy Intake) ///
       title(Figure: Scatter of EI and EER, size(medsmall)) ///
          scheme(test3) ///
          legend(order( 0 "normal" 1 "under")) ///
          graphregion(color(white))
      Now it should be simple to include a third plot specification (report_BC1_1sd==2) as line 3.

      Hope this helps.
      Svend

      Comment

      Working...
      X