Visualize your data
Work with your chart 2
11. Bar color and borders
Check yourself

Instruction

Histogram bars are differentiated by borders, but right now we can't see any borders on our chart. They're there, but the border color is the same as the bar color. This is a problem; if the bars don't differ in length, we can't separate them visually. (See the last two bars as an example; as they are now, they are indistinguishable.)

Let's fix this by changing the border color. You can also change the color of the bars to make them stand out from the rest of the chart. By doing this, we will make the bars easier to read and the chart more pleasing to look at.

Bar color borders

To change the color of bars and bar borders, we add two more arguments to geom_histogram(), as shown below:

+ geom_histogram(breaks = some_parameters, col = "your_color1", fill="your_color2")

The fill argument sets the bar color, and the col argument sets the border color.

Exercise

Change the color of bars and borders in our histogram. You can use any color on our Color card, which is located in the right sidebar. Click on a color and you will see its name.

The code from the previous exercise is still in the console; enter the names of the colors you've chosen where the your_color1 and your_color2 placeholder texts are.

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

Stuck? Here's a hint!

You should write:

hist <- ggplot(alcohol_consumption, aes(x = consumption)) + 
  geom_histogram(breaks = seq(0, 15, by = 1), 
    col = "white", 
    fill = "lightblue2")