To make a pretty histogram with ggplot2 in r, first we need some data to work with. Let's use the mpg
dataset from ggplot2
package.
main.r132 chars9 lines
This will generate a basic histogram, but it's not very pretty. We can improve the appearance of the plot by tweaking the parameters and adding a theme.
main.r210 chars6 lines
Here, we customized the plot by specifying the fill and color of the bars, adding a title and axis labels, and applying a theme. In this case, we use theme_minimal()
to remove the background grid and other default formatting, but you can choose from several built-in themes or create your own.
This should give us a pretty histogram that showcases our data effectively.
gistlibby LogSnag