Announcement

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

  • Twoway graph - "Border" on top and right axis

    I have a twoway graph with simple lines (my original graph looks a bit more "complicated" than the one attached) and I would like to have a "border" around the plot region. Basically I just would like to have the black line of the x-axis also on top of the graph and the black line of the y-axis also on the right side.

    There is a thread on that question (https://www.statalist.org/forums/for...-to-avoid-that), but the solution proposed there doesn't solve the problem and leads to an ugly graph (see blue circles in the attached graph).

    Command for the original graph:
    Code:
    twoway ///
    tsline series1 series2 series3 series4, ///
    lcolor(cranberry lavender orange black) xlabel(56 215, format(%tq)) ylabel(0.5 1 1.5) xsize(5) ysize(4) graphregion(color(white) margin(5 5 5 5)) ///
    legend(off) tlabel(1975q1(20)2011q2,grid nolabel) scheme(s2color)
    Command based on the proposed solution (changes are bold):
    Code:
    twoway ///
    tsline series1 series2 series3 series4, ///
    lcolor(cranberry lavender orange black) xlabel(56 215, format(%tq)) ylabel(0.5 1 1.5, nogextend) xsize(5) ysize(4) graphregion(color(white) margin(5 5 5 5)) plotregion(lcolor(black)) ///
    legend(off) tlabel(1975q1(20)2011q2,grid nolabel) scheme(s2color)
    Is there a way to achieve what I want?
    Attached Files

  • #2
    One way is to create a second "invisible" graph with empty alternate axes. The variables x & y here create a point in your plot region that we graph with -scatter-, but make the point "invisible" with -msymbol(i)-.
    Code:
    sysuse tsline1
    gen x=56
    gen y=1
    twoway ///
    tsline ar ma, ///
    lcolor(cranberry lavender orange black) xlabel(56 215, format(%tq)) ///
    ylabel(0.5 1 1.5) xsize(5) ysize(4) graphregion(color(white) ///
    margin(5 5 5 5))  ///
    legend(off) tlabel(1975q1(20)2011q2,grid nolabel) scheme(s2color) || ///
    scatter y x, msymbol(i) yaxis(2) xaxis(2) ///
    ylab(, axis(2) notick nolab) xlab(, axis(2) notick nolab) ytitle("", axis(2)) xtitle("", axis(2))
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      I think what you want is to add nogextend to your xlabel() option as well.

      Alternatively, you could remove nogextend from your ylabel() option. The problem the is that the grid appears "on top of" the border line, which leads to the border line having grid-colored spots where the grid intersects. If that's the case, perhaps someone else can advise further. I personally prefer the narrow white band between the grid and the border.

      Here is the reproducible example I have been playing with.
      Code:
      // use sample dataset running from 1jan2002 through 31dec2002
      sysuse tsline2, clear
      // adding 1jan2003 so the rightmost grid line gets drawn :-(
      expand 2 in l
      replace day = day+1 in l
      tsset day
      // draw the graph
      tsline calories, plotregion(lcolor(black)) ///
      xlabel(,grid nogextend ) ylabel(,grid nogextend )
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	282.3 KB
ID:	1460601

      Last edited by William Lisowski; 02 Sep 2018, 09:31.

      Comment


      • #4
        Thanks William Lisowski, that works perfectly!

        Comment

        Working...
        X