4
$\begingroup$

I would like to create this graph :

Population regression function

So I started with this :

    Clear[droite, norm1, norm2, norm3, hsGPA, graphdroite];

droite[hsGPA_] := 1.5 + 0.5*hsGPA

norm1 = Rotate[Plot[PDF[NormalDistribution[droite@4,.05], y], {y, 2, 6}, 
    PlotRange -> All, Axes -> False], 270 Degree];

norm2 = Rotate[Plot[PDF[NormalDistribution[droite@6,.05], y], {y, 4, 8}, 
    PlotRange -> All, Axes -> False], 270 Degree];

norm3 = Rotate[Plot[PDF[NormalDistribution[droite@8,.05], y], {y, 6, 10}, 
    PlotRange -> All, Axes -> False], 270 Degree];

graphdroite = Plot[droite[hsGPA], {hsGPA, 0, 10}]

Show[graphdroite, norm1, norm2, norm3]

But the Show function doesn't work here.

Any suggestions?

$\endgroup$

3 Answers 3

7
$\begingroup$

with Inset

  Plot[x, {x, 0, 1}, Epilog ->
      Table[
       Inset[Plot[Exp[-x^2], {x, -2, 2}, Axes -> {True, False}],
         {x, x}, {0, 0}, .25, {0, 1}], {x, .25, .75, .25}]]

enter image description here

( actually I'm pretty sure this is a dup but cant find it readily )

$\endgroup$
5
$\begingroup$

I really don't like the way that Rotate effects Graphics objects. You can't combine them with other Graphics objects since they now have the Head Rotate.

If you are making a y-axis plot, just use ParametricPlot instead:

ParametricPlot[{{y, 1.5 + .5 y},
  {3 + Exp[-(y - 5)^2/5], .2 y + 2.5},
  {6 + Exp[-(y - 5)^2/5], .2 y + 4}
  }, {y, 0, 10}, PlotStyle -> ColorData[97][1]]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Ok thanks, that looks neat. But would you know how to have the normal plots starting at a different horizontal level? I mean like in the picture I linked with the question. $\endgroup$
    – E Bassal
    Aug 24, 2016 at 20:42
  • $\begingroup$ @EBassal Have a look at the documentation for ParametricPlot, you should be able to make it work. $\endgroup$
    – Jason B.
    Aug 24, 2016 at 21:02
3
$\begingroup$

I've used gaussians here, but this should give you one idea of how to proceed.

    x0 = {2, 4, 7};
    y0 = {2, 4, 8};
    σ = {1.2, 1, 0.5};
    Show[
     ParametricPlot[
      Evaluate[
       {#1 + Exp[-y^2/#3], y + #2} & @@@ Transpose@{x0, y0, σ}
       ]
      , {y, -2*Max[σ], 2*Max[σ]}
      , PlotStyle -> Blue
      , AspectRatio -> 1/2
      , PlotRange -> {{0, 10}, {0, 10}}
      , LabelStyle -> Directive[FontSize -> 14]
      , Ticks -> {MapIndexed[{#1, "x" <> ToString@First@#2} &, x0], None}
      , AxesLabel -> {None, "y"}
      , ImageSize -> 400
      ]
     , Plot[x, {x, 0, 10}, PlotStyle -> Blue]
     ]

Which gives:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.