File:Geom bar reorder.png
Appearance
Geom_bar_reorder.png (559 × 414 pixels, file size: 15 KB, MIME type: image/png)
Summary
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()
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 14:54, 13 August 2024 | 559 × 414 (15 KB) | Brb (talk | contribs) | <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> |
You cannot overwrite this file.
File usage
The following page uses this file:
