Announcement

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

  • Graph with two y axes, one linear and one inverse

    Hello,

    I would like to generate a graph where one y-axis scale is linear (0 to x), and the opposite (yaxis(2)) scale is the inverse of this (1/x), and hence in reverse. An example of what I want to achieve is below. Lets take the variables being NNT (left y axis), ARR (right y axis) and _t (x axis) for the example below. Many thanks in advance.
    Click image for larger version

Name:	Altman figure.png
Views:	1
Size:	102.4 KB
ID:	1714945

  • #2
    The trick is to plot in terms of the reciprocal but to arrange for axis labels to show values on the original scale. See

    https://journals.sagepub.com/doi/pdf...867X0800800113

    https://journals.sagepub.com/doi/pdf...6867X221141058 -- write-up of mylabels (used below)

    You need a two step given NNT and its bad sibling.

    This isn't the graph you want, but it has the desired labels on the left.

    Code:
    clear 
    set obs 7
    gen x = _n 
    range whatever -0.1 0.5 
    
    gen NNT = 1/whatever 
    
    mylabels 2 5 10 20, myscale(1/@) local(yla1)
    
    mylabels 20 10, myscale(-1/@) local(yla2)
    
    scatter whatever x, yla(`yla1' `yla2')

    Comment


    • #3
      Thanks very much Nick Cox , that worked great!

      Comment

      Working...
      X