I'd like to reproduce the following base barplot, using ggplot2::geom_bar()
.
Toy data :
set.seed(314)
dat <- data.frame("Player" = rep(c("P1", "P2", "P3", "P4", "P5"), times = 2),
"Score" = runif(n = 10, 0, 10) * 3)
base barplot : the variable Player
is duplicated
barplot(height = dat$Score, names.arg = dat$Player)
geom_bar : the variable Player
is grouped
ggplot(dat) +
geom_bar(aes(x = Player, y = Score), stat = "identity")
How to use geom_bar()
so that the variable is duplicated (and not grouped) ? What am I missing ?
EDIT :
I changed the code of the base barplot to reorder the data and make more explicit the difference between the 2 functions : I am not sure that the following plot is reproducible using ggplot2 (without any tricks on the data itself).
barplot(height = dat[order(dat$Score, decreasing = TRUE), "Score"],
names.arg = dat[order(dat$Score, decreasing = TRUE), "Player"])