To style a histogram with ggplot2
in R, you can use the geom_histogram()
function. Here is an example code to create a basic histogram and style it:
main.r267 chars13 lines
In this example, we first load the ggplot2
library. Then, we create some example data using the rnorm()
function. We pass the data to ggplot()
function with the x-axis variable x
specified in the aes()
function. We then add the geom_histogram()
layer to create the histogram, specifying the fill color, outline color, and bin width. We also add a title, x and y axis labels, and a theme to style the plot.
You can customize other aspects of the histogram such as bin counts, axis limits, and text formatting using additional ggplot2
functions and arguments.
gistlibby LogSnag