How can I plot a grouped barplot in ggplot based on frequency?

JAdel

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:

enter image description here

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)
Maël

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.

edited at
0

Comments

0 comments
Login to comment

Related

How can I plot the mean of a feature in a barplot?

How to plot a barplot using ggplot

How can I create a frequency plot/histogram in R using ggplot2 while normalizing to the total of a factor?

How can I draw a grouped bar plot?

How to colour grouped barplot by group, not by conditon in ggplot?

How can I do grouped boxplots with ggplot?

ggplot Grouped barplot with R

How do I create a grouped percent plot in R using ggplot?

How can I plot a histogram with read_excel and barplot?

How to plot a barplot using ggplot2

How to Plot the Frequency of Two Character Variables on One Barplot Overlaid with Transparency

How can I plot bounding boxes in ggplot?

How can I plot the residuals of lm() with ggplot?

How can I add a legend to this plot (with ggplot())?

How can I increase the frequency of xticks/ labels for dates on a bar plot?

How can I add the overall histogram in a grouped histogram plot

How can I make a grouped range plot for a time series?

How can I plot hourly averaged time series grouped by month?

How to add frequency percentages to a ordered barplot in ggplot2

ggplot2 barplot in R with grouped column, how to unstack?

How can I make a grouped bar chart in ggplot?

How can I color bars in a faceted and grouped ggplot

how can I add multiple pvalues to ggplot grouped boxplot

How can I use the ggplot function to visualise grouped data?

How to plot a Stacked and grouped bar chart in ggplot?

How to plot with ggplot grouped data in two levels?

How do I create a one-row barplot/heatmap in which I can plot the values of my timepoints?

How to plot histogram in R based on frequency

How to create a grouped cumulative frequency graph with ggplot2