Minimal systems of generators for finitely generated algebras over commutative (graded) rings 
Let $S$ be some base ring (a commutative ring or even just a field), and $R$ a commutative ring containing $S$ which is finitely generated (as an algebra) over $S$. What conditions guarantee that any two minimal systems of generators of $R$ over $S$ have the same size?

I'm especially interested in a geometric picture to explain the situation, and whether it links to other geometrical ideas such as height or the Cohen-Macaulay property.

I'd also like to know what happens for graded rings - for instance, when are the degrees of two minimal systems of homogeneous generators the same (up to permutation)? 

What's the geometry behind this?
 A: I think this almost never happens without grading. Consider the simple example with 
$S=\mathbb Q$ and $R=\mathbb Q[X]$. Then $\{ X\}$ and $\{ X^2+X, X^2\}$ 
are minimal systems of generators of different sizes. Similar constructions should
work for any algebra over a field with a transcendental element.  
Of course if $R/S$ is a finite extension of prime order, then any minimal system of generators is a singleton. But this fails as soon as we remove the condition of prime order: let $S=\mathbb Q$
and  $R=\mathbb Q[\sqrt{2}, \sqrt{3}]$. Then $\{\sqrt{2}, \sqrt{3}\}$ and $\{ \sqrt{2}+\sqrt{3}\}$ are minimal systems of generators of different sizes. 

Graded case.   
For a homogeneous algebra $R$ over a field $S$, a set of homogeneous elements of $R$ generates $R$ if and only if it contains a set of generators of $R_1$ has vector space. So the minimal systems are exactly the basis of $R_1$ as $S$-vector space. 
More generally, if $R$ is a positive graded algebra over a field $S$, we can describe the minimal systems of homogeneous generators as follows. For any $d\ge 1$, denote by $R'_d$ the subvector space of $R_d$ generated by products of homogeneous elements of lower degrees ($R'_1=0$). Then $F\subset R$ is a minimal system of homogeneous generators if and only if for all $d\ge 1$, $F\cap R_d$ is a lifting of a basis of $R_d/R'_d$. In particular, for all $d\ge 1$, any two such systems share the same number of elements of degree $d$. 
A: For a connected, non-negatively graded algebra $A$ over a field, we can compute $Tor_1^A(k,k)$, which is a graded vector space: this is is isomorphic to every minimal space of homogeneous generators of $A$.
