Can a nowhere continuous function have a connected graph?

Here is an example for $\mathbb R^2 \to \mathbb R$:

$$f(x,y) = \begin{cases} y & \text{when }x=0\text{ or }x=1 \\ x & \text{when }x\in(0,1)\text{ and }y=0 \\ 1-x &\text{when }x\in(0,1)\text{ and } y=x(1-x) \\ x(1-x) & \text{when }x\notin\{0,1\}\text{ and } y/x(1-x) \notin\mathbb Q \\ 0 & \text{otherwise} \end{cases} $$

This is easily seen to be everywhere discontinuous. But its graph is path-connected.


A similar but simpler construction, also $\mathbb R^2\to\mathbb R$:

$$ \begin{align} g(1 + r\cos\theta, r\sin\theta) = r & \quad\text{for }r>0,\; \theta\in\mathbb Q\cap[0,\pi] \\ g(r\cos\theta, r\sin\theta) =r & \quad \text{for }r>0,\; \theta\in\mathbb Q\cap[\pi,2\pi] \\ g(x,y) =0 & \quad\text{everywhere else} \end{align} $$


Check out this paper:

F. B. Jones, Totally discontinuous linear functions whose graphs are connected, November 23, (1940).

Abstract:

Cauchy discovered before 1821 that a function satisfying the equation $$ f(x)+f(y)=f(x+y) $$ is either continuous or totally discontinuous. After Hamel showed the existence of a discontinuous function, many mathematicians have concerned themselves with problems arising from the study of such functions. However, the following question seems to have gone unanswered: Since the plane image of such a function (the graph of $y =f(x)$) must either be connected or be totally disconnected, must the function be continuous if its image is connected? The answer is no.

In particular, Theorem 5 presents a nowhere continuous function $f:\Bbb R \rightarrow \Bbb R$ whose graph is connected.


Whether Conway base 13 function is such an example remains unknown. (at least on MSE; see Is the graph of the Conway base 13 function connected?) It turns out the graph of Conway base 13 function is totally disconnected. See this brilliant answer.


There is a simple general strategy for many questions of this type, which is to just try to build a counterexample by transfinite induction. Let's first think about what it means for the graph $G$ of a function $f:\mathbb{R}\to\mathbb{R}$ to be disconnected. It means there are open sets $U,V\subset\mathbb{R}^2$ such that $U\cap G$ and $V\cap G$ are both nonempty and together they form a partition of $G$ (we will say $(U,V)$ separates $G$ in that case). So, to make $G$ connected, we just have to one-by-one rule out every such pair $(U,V)$ from separating it.

So, then, here is the construction. Fix an enumeration $(U_\alpha,V_\alpha)_{\alpha<\mathfrak{c}}$ of all pairs of open subsets of $\mathbb{R}^2$. By a transfinite recursion of length $\mathfrak{c}$ we define values of a function $f:\mathbb{R}\to\mathbb{R}$. At the $\alpha$th step, we add a new value of $f$ to prevent $(U_\alpha,V_\alpha)$ from separating the graph of $f$, if necessary. How do we do that? Well, if possible, we define a new value of $f$ such that the corresponding point in the graph $G$ will either be in $U_\alpha\cap V_\alpha$ or not be in $U_\alpha\cup V_\alpha$, so $U_\alpha\cap G$ and $V_\alpha\cap G$ will not partition $G$.

If this is not possible, then $U_\alpha$ and $V_\alpha$ must partition $A\times\mathbb{R}$ where $A\subseteq\mathbb{R}$ is the set of points where we have not yet defined $f$. Since $\mathbb{R}$ is connected, this means we can partition $A$ into sets $B$ and $C$ (both open in $A$) such that $U_\alpha\cap (A\times\mathbb{R})=B\times\mathbb{R}$ and $V_\alpha\cap (A\times\mathbb{R})=C\times\mathbb{R}$. Now since we have defined fewer than $\mathfrak{c}$ values of $f$ so far in this construction, $|\mathbb{R}\setminus A|<\mathfrak{c}$ and in particular $A$ is dense in $\mathbb{R}$. If $B$ were empty, then $U_\alpha$ would have empty interior and thus would be empty, and so $(U_\alpha,V_\alpha)$ can never separate the graph of $f$. A similar conclusion holds if $C$ is empty, so let us assume both $B$ and $C$ are nonempty. It follows that $\overline{B}$ and $\overline{C}$ cannot be disjoint (otherwise they would be a nontrivial partition of $\mathbb{R}$ into closed subsets), so there is a point $x\in\mathbb{R}\setminus A$ that is an accumulation point of both $B$ and $C$. Since $x\not\in A$, we have already defined $f(x)$. Note now that $(x,f(x))\not\in U_\alpha$, since $U_\alpha$ would then contain an open ball around $(x,f(x))$ and thus would intersect $C\times\mathbb{R}$. Similarly, $(x,f(x))\not\in V_\alpha$. Thus $U_\alpha$ and $V_\alpha$ already do not contain the entire graph of $f$, and so we do not need to do anything to prevent them from separating it.

At the end of this construction we will have a partial function $\mathbb{R}\to\mathbb{R}$ such that by construction, its graph is not separated by any pair of open subsets of $\mathbb{R}^2$, and the same is guaranteed to hold for any extension of our function. Extending to a total function, we get a total function $f:\mathbb{R}\to\mathbb{R}$ whose graph is connected. But we can of course arrange in this construction for $f$ to be nowhere continuous; for instance, we could start out by defining $f$ on all the rationals so that the image of every open interval is dense in $\mathbb{R}$. In fact, the construction shows that any partial function $\mathbb{R}\to\mathbb{R}$ defined on a set of cardinality less than $\mathfrak{c}$ can be extended to a total function whose graph is connected. (Or even stronger, you could start with any partial function whose domain omits $\mathfrak{c}$ points from every interval, since that is all you need to guarantee that the set $A$ is dense at each step.)