I have the below plot of the joint density of X and Y. X and Y are continuous random variables. X takes on values between 0 and 2 while Y takes on values between 0 and 1.
Can someone please explain to me how does someone go about getting the marginal density of X simply by looking at the plot of the joints?
The answer to the question is given by the below expression:
$f_{X}(x)=\left\{\begin{array}{ll}{x / 2,} & {\text { if } 0 \leq x \leq 1} \\ {-3 x / 2+3,} & {\text { if } 1<x \leq 2} \\ {0,} & {\text { otherwise }}\end{array}\right.$
But if someone can please explain how does one arrive at it.
Thanks,

Since $f_{X,Y}(x,y)$ depends on two variables you have to imagine the function as two plateaus with height $1/2$ and $3/2$ above the corresponding triangles, and zero everywhere else (which I didn't plot):
Now, in order to compute the marginal $$ f_X(x) = \int_{-\infty}^{\infty} f_{X,Y}(x,y)\, \mathrm dy $$ you have to imagine (the area of) the cross sections for every $x$ separately (I plotted two possible choices of $x$):
If you know what to do, you can also perform these steps in your head by looking at your original drawing:
What is left is to figure out for each $x$ the corresponding height $\ell$ and take the area of the crossection, which is $\ell\cdot \frac{1}{2}$ for $x\le 1$ and $\ell\cdot \frac{3}{2}$ for $x>1$. This gives you your answer.