To create a side-by-side bar plot in R using ggplot2, you can use the position_dodge()
function to create a dodge position adjustment of the objects being stacked. Here's an example code:
main.r347 chars13 lines
In this example, the geom_col()
function is used to create the bar plot with position = position_dodge(width = 0.9)
to adjust the position of the bars so they are side-by-side. width
is the amount of space between the bars (0.9 is the default), and alpha
controls the opacity of the bars (0-1).
The theme_classic()
function is used to apply a classic ggplot2 theme to the plot.
gistlibby LogSnag