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.)