Blog Home

R 2.4.3 Exercises

From R for Data Science

Exercises 2.4.3

It’s fun to have fun but you have to know how. ~ The Cat in the Hat

1-Make a bar plot of species of penguins, where you assign species to the y aesthetic. How is this plot different?


 ggplot(penguins, aes(y=species))  +  geom_bar()

The x and y axes are reversed, and the bars are horizontal instead of vertical

2-How are the following two plots different? Which aesthetic, color or fill, is more useful for changing the color of bars?

> ggplot(penguins, aes(x = species)) +
      geom_bar(color = "red")

> ggplot(penguins, aes(x = species)) +
      geom_bar(fill = "red")

The color=”red” code changes the outline of the bars to red; the fill=”red” code changes the bar itself to red color. The fill=”red” is more useful for changing the color of the bars.

3-What does the bins argument in geom_histogram() do?

It changes the groupings of data on the x axis, or how the x axis values are divided equally.