Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualization using boxplot for large datasets

I have a dataframe in the following format.

item    price
item1    23
item2    45
item1    24
item3    98
item2    45.9
item3    97.2

From this, I need to display boxplots of price distribution for every unique item in the item column. There are about 80 unique items. So, I am not sure how to group them such that I get boxplots with atleast 4 unique item's with its range in each graph and multiple such graphs for all the 80 unique items. I am not sure if I should reshape my dataframe and even if I need to , on what basis would it be? I have tried with facet_wrap but the nrow is not making any difference. Any help with this will be much appreciated.

Thanks in advance.

like image 624
savi Avatar asked May 17 '26 15:05

savi


1 Answers

You'll need to make a grouping variable based on your item names. Since all of your items in the example are called item#, I just pulled the number from them to make a grouping var:

df <- df %>%
  mutate(group = gsub("item", "", item))

p <- ggplot(df, aes(x=item, y=price)) + 
  geom_boxplot() +
  facet_wrap(item~group,scales="free")
p
like image 130
Matt Avatar answered May 19 '26 05:05

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!