I have a problem with the following
Let $X$ be a compact subset of $\mathbb{R}$ and let $f$ be a real-valued function on $X$. Prove that $f$ is continuous if and only if $\{(x,f(x)) \mid x\in X\}$ is compact subset of ${\mathbb R}^2$.
I have done $\Rightarrow$ direction but with the other direction I could use some help.
For the $\,"\Longleftarrow"\,$ direction we use proof by contradiction.
If not, let $x_n\to x$, while $f(x_n)\not\to f(x)$. This implies that there exists an $\varepsilon>0$ and a subsequence $\{f(x_{k_n})\}_{n\in\mathbb N}$ with the property $$ \lvert \,f(x_{k_n})-f(x)\rvert\ge\varepsilon. $$ But as the graph $\mathscr G(f)$ of $f$ is compact, so is its $y-$projection, and hence $\{f(x_{k_n})\}_{n\in\mathbb N}$ possesses a convergent subsequence, call it $\{f(y_n)\}_{n\in\mathbb N}$, and the limit is $z\ne f(x)$. So, since $\mathscr G(f)$ is compact, then we have $$ \big(y_n,f(y_n)\big)\to (x,z)\in\mathscr G(f). $$
But this is a contradiction, as $f$ is a function, and $$ \big(x,f(x)\big),\, (x,z)\in\mathscr G(f). $$