I want to plot a grouped barplot with the values avg_r
and price_l
, but based on the frequency of price_l
. I tried something like this:
g1 <- ggplot(sub.dt, aes(fill=price_l, y=seq(0,24,1), x=avg_r)) +
geom_bar(position="dodge", stat="identity")
g1
Which gives me that:
So, for example 2.5 should be at 1 at the y axis. Here is some code for reproduction:
price_l <- c('€€-€€€', '€€-€€€', '€€€€', '€€-€€€', '€€-€€€',
'€€-€€€', '€€€€', '€€-€€€', '€€€€', '€€-€€€',
'€€-€€€', '€€-€€€', '€€-€€€', '€€-€€€',
'€€-€€€', '€€-€€€', '€€-€€€', '€€-€€€', '€€€€','€', '€',
'€', '€','€€€€', '€')
avg_r <- c('4.5', '3.5', '4.0', '4.0', '4.0', '3.5', '4.5', '4.0', '3.0', '4.0',
'3.0', '5.0', '4.5', '4.0', '3.0',
'3.5', '4.5', '3.5', '3.5', '4.0', '3.0', '4.0', '4.0', '2.5', '4.5')
sub.dt <- data.table(price_l, avg_r)
Use stat = "count"
:
ggplot(sub.dt, aes(fill=price_l, x=avg_r)) +
geom_bar(position="dodge", stat="count")
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments