Compute the quantile function of this distribution I want to compute the quantile function of a Bin(4, 1/3)  random variable and plot it with R, but I don't know where to start from.
Any help or hint is highly appreciated.

Note that the probability mass function is
$$
f(x) = P(X = x) = 
\begin{cases}
 \frac{16}{81}&\text{if  } x=0\\
\frac{32}{81}&\text{if  } x=1\\
 \frac{24}{81}&\text{if  } x=2\\
 \frac{8}{81}&\text{if  } x=3\\
  \frac{1}{81}&\text{if  } x=4,
\end{cases}
$$
and the cumulative distribution function is
$$
F(x) = 
\begin{cases}
0 & \text{if  } x<0\\
\frac{16}{81}  &\text{if  } 0\leq x < 1\\
\frac{48}{81}  &\text{if  } 1\leq x < 2\\
\frac{72}{81}  &\text{if  } 2\leq x < 3\\
\frac{80}{81}  &\text{if  } 3\leq x < 4\\
1  &\text{if  }  4\leq x.
\end{cases}
$$
The quantile function $Q$ is thus
$$
Q(p) = 
\begin{cases}
0 & \text{if  } 0< p \leq \frac{16}{81}\\
\cdots & \cdots\\
4 & \text{if  } \frac{80}{81}< p.
\end{cases}
$$
I leave the rest, e.g. the $\cdots$, to you.

R code
plot(1, xlim=c(0,1), ylim=c(-1,5), type="n",
     xlab= "p", ylab= "Q(p)", main = "X ~ Bin(4,1/3)")
abline(v=c(0,1), lwd=1, lty=2, col="lightgray")
segments(x0=0,x1=16/81,y0=0,y1=0, lwd=2)
points(x=16/81,y=0, pch=20, cex=1.4)
#+++++++
segments(x0=16/81,x1=48/81,y0=1,y1=1, lwd=2)
points(x=48/81,y=1, pch=20, cex=1.4)
#+++++++
segments(x0=48/81,x1=72/81,y0=2,y1=2, lwd=2)
points(x=72/81,y=2, pch=20, cex=1.4)
#+++++++
segments(x0=72/81,x1=80/81,y0=3,y1=3, lwd=2)
points(x=80/81,y=3, pch=20, cex=1.4)
#+++++++
segments(x0=80/81,x1=81/81,y0=4,y1=4, lwd=2)

