Odd coloring of sparse graphs and planar graphs