# Closed immersion and the graph of morphism.

Let $f:X\rightarrow Y$ be a morphism of $S$-schemes and $\Gamma_f:X\to X\times_SY$ be the morphism iduced by $\text{id}_X:X\to X$, $f:X\to Y$. Obviously, $\Gamma_f$ is a closed immersion when $\Delta_{Y/S}:Y\to Y\times_SY$ is a closed immersion since closed immersion is stable under base change. But how can I prove $\Delta_{Y/S}$ is a closed immersion when $\Gamma_f$ is a closed immersion?

A reference states, we can prove the converse with the fact that below commuting diagram is a cartesion. $$\begin{matrix} X & \stackrel{f}{\longrightarrow} & Y\\ \downarrow \Gamma_f &&\downarrow \Delta_{Y/S}\\ X\times_SY&\stackrel{f\times_S \text{id}_Y}{\longrightarrow}& Y\times_SY \end{matrix}$$

But I cannot derive the result just with these.

$X=\emptyset$ and $Y/S$ non-separated provides a counterexample.