I can't seem to find an example of a function $f \colon \mathbb{R}^2\to \mathbb{R}$ which is $C^1$ and such that the set of its critical values is not of zero measure.
What examples are there? $\phantom{aaa}$
I can't seem to find an example of a function $f \colon \mathbb{R}^2\to \mathbb{R}$ which is $C^1$ and such that the set of its critical values is not of zero measure.
What examples are there? $\phantom{aaa}$
My favourite example is as follows. Let the simple curve $\kappa:[0,1]\to K\subset \mathbb{R}^2$ be a parametrization of (half of) the Koch curve, and let $\phi:K\to[0,1]$ be its inverse; it is a continuous function, and, due to the fact that $\kappa$ has infinite variation on any non-empty interval $J\subset [0,1]$, it can be chosen in such a way that it satisfies $$|\phi(x)-\phi(y)|=o(|x-y|)$$ uniformly on $K$. Therefore the data $\phi$ together with the zero field on $K$ satisfy the hypotheses of the Whitney extension theorem for the case of $C^1$ regularity. Thus $\phi$ extends to a $C^1$ function $f:\mathbb{R}^2\to\mathbb{R}$ whose gradient vanishes identically on $K$.
$$*$$ Details. The standard parametrization of the Koch curve may be defined as the unique bounded function $\kappa:[0,1]\to\mathbb{C}$ satisfying the (linear, non-homogeneous) functional equation
$$3\kappa(x)=\cases{\kappa(4x)& if $\;0\le x< {1\over4}$\\\\ 1+e^{i\pi/3}\kappa(4x-1)& if $\;{1\over4}\le x< {2\over4}$\\\\ 1+e^{i\pi/3}-e^{i\pi/3}\kappa(4x-2)& if $\;{2\over4}\le x< {3\over4}$\\\\ 2+\kappa(4x-3)& if $\;{3\over4}\le x\le 1$}$$
that is $\kappa$ is the fixed point of an affine $1/3$-norm contraction on the Banach space of $\mathbb{C}$-valued bounded functions on $[0,1]$, whence its existence and uniqueness. It also follows from this, that $\kappa$ is $\alpha$-Hölder, with $\alpha:={\log3\over\log4}$, and in fact, for some constants $0<c<C$ it verifies, for all $x$ and $y$ in $[0,1]$ $$c|x-y|^\alpha\le|\kappa(x)-\kappa(y)|\le C|x-y|^\alpha,$$
which implies that its inverse $\phi$ satisfies a Hölder condition with exponent $1/\alpha$, larger than $1$ (a phenomenon that is not possible for non-constant functions on an interval, or more generally on metric spaces connected by rectifiable curves); in particular, it satisfies the stated $|\phi(x)-\phi(y)|=o(|x-y|)$.
If $f\in C^1(\mathbb{R}^2,\mathbb{R})$, then the set of critical values may have positive measure.
The classical construction due to Whitney was mentioned in the answer by T. Amdeberhan. However, the simplest one is due to E.L.Grinberg. The idea is as follows:
If $C$ is the Cantor middle thirds set, then $C+C=[0,2]$.
There is a $C^1$ function $g:\mathbb{R}\to\mathbb{R}$ such that the critical values of $g$ contain $C$.
Now $f:\mathbb{R}^2\to\mathbb{R}$ defined by $f(x,y)=g(x)+g(y)$ is of class $C^1$ and $C+C=[0,2]$ is contained in the set of critical values of $f$.
This has been known for some time, including the higher-dimensional problem, in $\mathbb{R}^n$, that if $f\in C^k$ where $k<n$ then the set of critical points need not be of zero measure.
H. Whitney, A function not constant on a connected set of its critical points, Duke Math. J. 1 (1935), 514-517.
I decided to challenge myself to make pictures of Piotr Hajlasz's example, partly for fun and partly for the next time I teach this. Let $C_3$ be the standard Cantor middle thirds set: $$C_3 = \left\{ \sum_{k=1}^{\infty} \frac{a_k}{3^k} : a_1, a_2, a_3, \cdots, \in \{ 0,2 \} \right\}.$$ Let $C_4$ be the variant "middle halves set" $$C_4 = \left\{ \sum_{k=1}^{\infty} \frac{b_k}{4^k} : b_1, b_2, b_3, \cdots, \in \{ 0,3 \} \right\}.$$ Note that every $z$ in $[0,1]$ can be written as $(2/3) x + (1/3) y$ for $x$, $y \in C_4$ in either $1$ or $2$ ways. Here is a drawing of $C_4 \times C_4$ and its intersection with the lines $(2/3)x + (1/3) y = k/16$ for $0 \leq k \leq 16$:
Here is a $C^1$ function $\phi(x)$ which maps $C_3$ to $C_4$ in an order preserving manner, with derivative $0$ at each point of $C_3$. On each interval of $[0,1] \setminus C_3$, it is an appropriately chosen sine curve.
And here is the final product, a depiction of the function $f(x,y) = (2/3) \phi(x) + (1/3) \phi(y)$. The level curves show $f(x,y) = k/16$ for $0 \leq k \leq 16$. The black dots are the critical points $C_3 \times C_3$; the red dots demonstrate how every level curve contains $1$ or $2$ critical points.