How to graph gravity as a function of depth, given radius and density?
As long as we deal with a spherically symmetric planet, the mass of the shell above you does not influence the observed gravity; the little mass close by exactly cancels the large amounts of mass far away (you would float inside a planet if it looked like a pingpong ball and had all its mass centered on the surface!), this is called Newton's Shell Theorem.

You can then compute $g$, acting as if the mass $M$ is concentrated at a point on the centre of the sphere. Thus, combining your knowledge of the mass $M$ underneath you, and the radius $r$ towards the center of this planet, you can compute the gravity field using the equation you give!

For a constant density we have a volume $V=\frac{4}{3}\pi r^3$, thus mass $M=\rho_1 V$, and the gravity is given as $g(r)=\frac{GM}{r^2}=G\frac{4}{3}\pi r \rho_1$, linear like you found. For two layers, it is a sum of this first mass $M_1=\frac{4}{3}\pi_1R_1^3$ and second mass $M_2=\frac{4}{3}\pi_2(r-R_1)^3$ but ONLY when this mass is below you, i.e.
$$g^*(r) = \begin{cases}G\frac{4}{3}\pi \rho_1 r &amp; r\leq R_1 \\ G\frac{4}{3}\pi( \rho_1\frac{R_1^3}{r^2}+\rho_2\frac{(r-R_1)^3}{r^2}) &amp; r&gt;R_1\end{cases}.$$
This should not be linear anymore due to the $R_1^3/r^2$ contribution!

Good luck!