Visualize your data
Work with your chart 2
12. Get rid of the clutter
Check yourself

Instruction

You can also adjust grids in a histogram. We almost always remove the categorical axis grid for other charts, but here we have a numerical variable presented on the horizontal axis. Do we have to keep the grid? You can if you think it's necessary. However, your chart will be less cluttered if you decide to remove it. (We're not giving you hard and fast rules here, just suggestions.) After adding borders to the bars, we can see where each bar starts and ends, so we don't need the grid to read specific intervals.

So how do we remove this grid? It's very like how we removed it from the bar chart. The difference is that the numerical axis grid in ggplot consists of two types of lines: major lines (which are usually thicker) and minor lines (which lie between the major lines). We have to remove each line type separately from the chart. We do this by adding this command:

+theme(panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank())

Setting the panel.grid.major.x to element_blank() will remove the major grid lines from the horizontal axis, and setting panel.grid.minor.x to element_blank() will remove the minor ones.

Exercise

Remove the horizontal axis grid lines by adding the above theme() command to your chart object hist.

When you're done, press the Run and Check Code button to check your code.

Stuck? Here's a hint!

You should write:

theme(panel.grid.major.x = element_blank(),
   panel.grid.minor.x = element_blank())