Suppose $Y$ is an affine variety in $\mathbb{A}^n$ of $\dim r$. Then height of the prime ideal $\mathcal{I}(Y)$ is $n-r$. We have a result:
"Let $A$ be a Noetherian ring, $x_1,\dots ,x_r\in A$. Then every minimal prime ideal $\mathfrak{p}$ belonging to $(x_1,\dots ,x_r)$ has height $\leq r$." (Atiyah-Macdonald, Corollary $11.16$, page $121$).
Now suppose $\mathcal{I}(Y)$ is generated by $m$ elements. Then, using the result, $n-r\leq m$. So $\mathcal{I}(Y)$ is minimally generated by $n-r$ elements.
$\underline{\text{My question}}$: Is it always possible to find $n-r$ elements which will generate $\mathcal{I}(Y)$ or there are some examples for which it is not possible to find that minimal number of elements ?
Also, in particular, if $Y$ is a linear variety then as @Georges pointed out we can always find $n-r$ elements which will generate the ideal $\mathcal{I}(Y)$. I need an explanation for this last part.
Thank you.