File:Geom bar reorder.png: Revision history

Jump to navigation Jump to search

Diff selection: Mark the radio buttons of the revisions to compare and hit enter or the button at the bottom.
Legend: (cur) = difference with latest revision, (prev) = difference with preceding revision, m = minor edit.

13 August 2024

  • curprev 15:5415:54, 13 August 2024Brb talk contribs 446 bytes +446 <syntaxhighlight lang='r'> library(ggplot2) library(forcats) data <- data.frame( category = c("A", "B", "C", "D"), value = c(3, 5, 2, 8) ) data$category <- fct_reorder(data$category, data$value) levels(data$category) # [1] "C" "A" "B" "D" ggplot(data, aes(x = category, y = value, fill = category)) + geom_bar(stat = "identity") + coord_flip() + labs(x = "Category", y = "Value") + theme_minimal() </syntaxhighlight>