Geometric meaning of completion and localization Let $R$ be a commutative ring with unit, $I$ an ideal of $R$ and consider the following three constructions.


*

*The localization $R_I$ of $R$ at $I$ (i.e. the localization of $R$ at the multiplicative system $R\setminus I$) gives a morphism
$$
f_1:\operatorname{Spec}(R_I)\to \operatorname{Spec}(R)=:X
$$

*The completion $\widehat{R}_I$ of $R$ at $I$ gives a morphism
$$
f_2:\operatorname{Spec}(\widehat{R}_I)\to X
$$

*For the special case $I=(a)$, the localization $R_a$ (i.e. the localization of $R$ at the multiplicative system $\{1,a,a^2,\ldots\}$) gives a morphism
$$
f_3:\operatorname{Spec}(R_a)\to X
$$


My question is:

What is the geometric meaning of all three constructions and how are they related?

This is what I ''know'' already or describes at least the style of answer I would appreciate. As remarked in the comments, $I$ has to be a prime ideal.


*

*$R\to R_I$ is injective iff $R\setminus I$ contains no zero divisors which is the case if $I$ is a prime ideal. The scheme $\operatorname{Spec}(R_I)$ is the intersection of all the neightbourhoods of $I$ in $X$. This is a little contra-intuitive for me since the last statement sounds like ''$f_1$ is injective'' but the $\operatorname{Spec}$-operator should turn 'injective'' and ''surjective'' around somehow (I know this is literally not true but I only want to get a feeling like ''is contained'', ''is bigger'', ''is smaller'', etc.).

*$\operatorname{Spec}(R_a)$ is somehow the opposite of $\operatorname{Spec}(R_{(a)})$ (= the intersection of all the neightbourhoods of $(a)$ in $X$) because $\operatorname{Spec}(R_a)$ seems to be something like the union of all the open sets of $X$ not containing the point $(a)$.

*$R\to\widehat{R}_I$ is injective iff $\cap I^n=(0)$ and this holds very often (e.g. for $R$ noetherian and either an integral domain or a local ring). Hence (this is probably false intuition as remarked before), $f_2$ should be something like a ''projection'' (from something ''big'' into something ''small''). But what is geometrically the difference between localization and completion. I don't have a geometric idea of completion at all.


As remarked by Qiaochu Yuan in the comments below, one should not think of $\operatorname{Spec}$ as injective-surjective switching.
 A: First of all, localization $R_I$ is only defined if $R\setminus I$ is actually a multiplicative system, i.e. if for $a\notin I$ and $b\notin I$, you have $ab\notin I$. that translates to $ab\in I$ $\Rightarrow$ $a\in I$ or $b\in I$, so $I$ has to be a prime ideal in any case. For intuition, I would advise thinking of $R$ as a finitely generated (and reduced) $k$-algebra, the quotient of the polynomial ring in $n$ variables over an algebraically closed field $k$: Then, $\mathrm{Spec}(R)$ (or at least the maximal ideals among the prime ideals) is just a subvariety of the affine space $k^n$. Think of $R$ as the functions on $X=\mathrm{Spec}(R)$.


*

*The ring $R_I$ is the ring where you are allowed to invert any function which is not in $I$: If $I$ is the ideal corresponding to a closed subvariety $Z=Z(I)$ of $X$, this means you may invert anything that does not vanish on $Z$. The intuition is that we think of $R_I$ as the functions that are defined locally around $Z$: If you have any function $f$ defined in a neighbourhood $U$ of $Z$ and it does not vanish on $Z$ itself, then by removing $Z(f)$ from $U$, you still have a neighbourhood of $Z$, but now $f$ is invertible everywhere on $U$. So, if you shrink the support of a function around $Z$ far enough, it is either a unit or it vanishes on $Z$. 
Recall that the prime ideals of $R_I$ are precisely the prime ideals of $R$ which do not meet $R\setminus I$, i.e. the ones that are contained in $I$. Those again correspond to subvarieties $Z'$ containing $Z$. So I personally think of $\mathrm{Spec}(R_I)$ as the space that parametrizes the $Z'$. 

*Let me quote Chapter 7 of David Eisenbud's book Commutative Algebra with a view toward algebraic geometry on this one:

A localization $R_I$ of the affine ring of a variety at the maximal ideal $I$ of a 
  point on the variety represents and reflects the properties of Zariski open 
  neighborhoods of the point; the completion $\hat R_I$ represents the properties 
  of the variety in far smaller neighborhoods. For example, over the complex numbers, the information available from $\hat R_I$ is (roughly speaking) infor- 
  mation about arbitrarily small neighborhoods in the "classical topology" 
  induced by the fact that the variety is a closed subspace of some $\mathbb C$ with 
  its ordinary topology. 

He follows it up with a nice example, I suggest you give it a look.

*Now this time, we are allowed to invert everything in $(a)$. In other words, you may divide by a function that before may have had zeros. What has happened geometrically? We have removed the zeros of that function from $X$. We think of $R_a$ as the regular  functions on the so-called standard open set $D(a)=X\setminus Z(a)$. Again, $\mathrm{Spec}$ passes us from functions to points and we think of $\mathrm{Spec}(R_a)$ as the open subvariety $X\setminus Z(a)$. That is, in fact, very accurate.

