Let $R$ be a commutative ring with $1$, and let $f \in R$ be an element of $R$ which is neither nilpotent, nor a unit (assuming there exists such an element in $R$). Let $R_f$ be the localization of $R$ with respect to the multiplicative subset $\{ f^n: n \in \mathbb{N} \}$. In this post, the relevant notion of dimension used is Krull dimension.
It is clear that $\dim R_f \leq \dim R$. I have two questions:
1) Are there some sufficient conditions that ensure equality of the dimensions, namely sufficient conditions to have $\dim R_f = \dim R$?
2) Does equality hold in general? If yes, can someone provide a proof please, and if not, can someone provide an example where $\dim R_f < \dim R$?
Edit 1: Following user26857's comment, let $R = \mathbb{C}[x]_{(x)}$. Let $f=x/1$. It is clear that $\dim R = 1$; indeed the only prime ideals of $R$ are $0$ and $(f)$. It follows easily that $\dim R_f = 0$, since the only prime ideal of $R$ which avoids the non-negative powers of $f$ is $0$. This answers my question 2, because in this example, we have $\dim R_f < \dim R$. (Remark: I had written a wrong example in my answer before, instead of this one, for which I apologize.)
Edit 2: Regarding question 1), following Mohan's comments, if $R$ is an integral domain which is a finitely generated algebra over a field or $\mathbb{Z}$, and if $f \in R$ is nonzero, then
$\dim R_f = \dim R$.
We thus have 2 cases to consider in this claim
case A: $R = k[x_1,\cdots,x_n]/P$, where $k$ is a field, and $P$ is a prime ideal in $k[x_1,\cdots,x_n]$.
case B: $R = \mathbb{Z}[x_1,\cdots,x_n]/P$, where $P$ is a prime ideal in $\mathbb{Z}[x_1,\cdots,x_n]$.
I will be happy if someone can post as answer a sketch of a proof of Mohan's claim. I think it amounts to showing that one can find a sequence of chains of prime ideals in R, with all prime ideals involved not containing $f$, and whose lengths go to $\dim R$.
I thank user26857 for his comments, which I am using to provide an answer to this post, in the hope it will be useful for others. I have learned a lot. Credit goes to user26857, and mistakes in this answer (if any) are my sole responsibility!
Definition 1. A commutative ring with 1 is said to be a Jacobson ring if every prime ideal is the intersection of the maximal ideals containing it.
Definition 2. A commutative ring with 1 $R$ is said to be equicodimensional if for every maximal ideal $\mathfrak{m}$ of $R$, $\dim R = \operatorname{ht}(\mathfrak{m})$.
Proposition. Let $R$ be an equicodimensional Jacobson commutative ring with 1, and let $f \in R$ be a non-nilpotent element. Then $\dim R_f = \dim R$.
Note: Since the examples mentioned by Mohan are equicodimensional Jacobson, namely if we have an integral domain which is a finitely generated algebra over a field or $\mathbb{Z}$, it follows that $\dim R_f = \dim R$ for these very important rings in particular.
Proof. I will follow user26857's sketch of a proof. Since $f$ is not nilpotent, then $f$ does not belong to the nilradical of $R$. Since $R$ is Jacobson, then its nilradical equals its Jacobson radical. Hence there exists some maximal ideal $\mathfrak{m}$ of $R$ such that $f \notin \mathfrak{m}$. Hence $\operatorname{ht}(\mathfrak{m}) = \operatorname{ht}(\mathfrak{m}_f)$, where $\mathfrak{m}_f$ denotes the extension of $\mathfrak{m}$ in $R_f$.
Since $R$ is equicodimensional, we also have that $\dim R = \operatorname{ht}(\mathfrak{m})$. But $\operatorname{ht}(\mathfrak{m}_f) \leq \dim R_f$, so that $\dim R \leq \dim R_f$, and thus $\dim R = \dim R_f$, as required.