plot barchart in ggplot in r

main.r
library(ggplot2)

# create example data
data <- data.frame(category = c("A", "B", "C"), 
                   count = c(10, 20, 15))

# create barchart using ggplot2
ggplot(data, aes(x = category, y = count)) +
  geom_bar(stat = "identity")
239 chars
10 lines

This code will create a barchart using ggplot2 in R. The data object is a simple data frame with the category labels in the category column and the corresponding counts in the count column.

The ggplot() function initializes the plot and defines the data object and the aes() (aesthetics) of the plot, mapping the category to the x-axis and count to the y-axis.

The geom_bar() function creates the bars of the barchart with stat = "identity" which means the heights of the bars will correspond to the count values in the data frame.

gistlibby LogSnag