You've got two triangles, and you want to map them linearly to two other triangles. So let's do that.
The upper left triangle, i.e. the $g > w$ case, is easy: the $g$ axis stays fixed, while the $w$ axis is simply scaled down by a factor of $p$, giving us the map $(w, g) \mapsto (pw, g)$.
The lower right triangle, where $g < w$, is slightly trickier. We can start by considering the case $p = 1$, where clearly the $g$ coordinate is squeezed out and the whole triangle simply mapped to the line $R = G = w$, giving us the degenerate map $(w, g) \mapsto (w, w)$. More generally, if $p < 1$, we'll still map the $w$ axis to that line, but we'll also have to subtract some multiple of $g$ from $R$ so that $(1,1)$ maps to $(p,1)$ instead of $(1,1)$. A bit of thinking shows that the correct scaling factor is $1-p$, giving us the map $(w, g) \mapsto (w - (1-p)g, w)$.
Putting these together, the full map is simply:
$$f(w,g) = \begin{cases}
(p w, g) & \text{if } g > w \\
(w - (1-p)g, w) & \text{otherwise}
\end{cases}$$
To make sure the resulting function is continuous, we can check that, on the boundary line $w = g$, the two pieces indeed join together:
$$w = g \implies w - (1-p)g = w - g + pg = pw$$
Ps. If you'd prefer something more systematic and generally applicable than the reasoning above, you can also derive these formulas using linear algebra.
The first step is to note that we're going to need a piecewise function composed of two linear (well, affine, actually) maps, one for each triangle. The second step to note is that any affine map $h: \mathbb R^2 \to \mathbb R$ can be written as:
$$h(x,y) = a + bx + cy$$
where $a$, $b$ and $c$ are constants. Since our output space is also two-dimensional, we're going to need two of these maps for each triangle, so that our final function will look like this:
$$f(w,g) = \begin{cases}
(a_{11} + b_{11}w + c_{11}g,\, a_{12} + b_{12}w + c_{12}g) & \text{if } (w, g) \in \text{triangle 1} \\
(a_{21} + b_{21}w + c_{21}g,\, a_{22} + b_{22}w + c_{22}g) & \text{if } (w, g) \in \text{triangle 2}
\end{cases}$$
Now, given the corner points of the original and mapped triangles, we can find the coefficients $a$, $b$ and $c$ for each triangle and each output coordinate by solving the system of three linear equations:
$$\begin{aligned}
Z_1 &= a + bw_1 + cg_1 \\
Z_2 &= a + bw_2 + cg_2 \\
Z_3 &= a + bw_3 + cg_3
\end{aligned}$$
where $(w_i, g_i)$ are the original coordinates of each corner points, $(R_i, G_i)$ are the coordinates of the transformed corner points, and $Z_i$ stands for either $R_i$ or $G_i$ depending on which coordinate we're solving the coefficients for.
So, for example, for the second triangle we have the known corner points $(0,0) \mapsto (0,0)$, $(1,0) \mapsto (1,1)$ and $(1,1) \mapsto (p,1)$, giving us the following equations for the $R$ output coordinate:
$$\begin{aligned}
0 &= a_{21} + b_{21}\cdot0 + c_{21}\cdot0 \\
1 &= a_{21} + b_{21}\cdot1 + c_{21}\cdot0 \\
p &= a_{21} + b_{21}\cdot1 + c_{21}\cdot1
\end{aligned}$$
You could solve this using e.g. Gaussian elimination, but in this case that would be overkill: it's obvious from the first equation that $a_{21} = 0$ and from the second equation that $b_{21} = 1$. Plugging those into the last equation then leaves us with $p = 1 + c_{21}$ and thus $c_{21} = p - 1$.
Repeating the process for the other three sets of coefficients is left as a simple exercise.