'How to use ggplot2 in R to plot a boxplot with number of observations?

With a data frame that has has a grouping column and a value column, plotting a grouped boxplot with ggplot2 is done like this

ggplot(data=data, aes(x = Grouping, y = Value, group = Grouping)) + geom_boxplot()

However, how would you plot a grouped boxplot when you have an extra column that designates the number of observations for that value/grouping pair? For example, for the below data frame, there are 17 data points for grouping A and 11 for grouping B, each with their respective value.

Grouping   Value   NumberObservations
A          1       10
B          1       2
A          2       7
B          2       9

Of course, another data frame can be created that contains 10 rows of grouping A and value 1 and so on to use the above ggplot method, but I want to avoid this because my data frame would get very large due to the number of observations. Is there a way to weight/add number of observations directly in a ggplot box plot?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source