diagram overload- split data into multiple charts

Hello everyone,
I have created a barplot with 149 bars. That is too much for a clear representation. Does anyone have an idea how I can display a maximum of 50 bars per diagram, i.e. 3 diagrams with 50, 50, 49 bars? Many thanks for your help!

Best regards, Paula

Define a grouping criteria that makes sense for your data and use facets or use a lollipop plot instead of bars.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

Thank you for your answer. Your're right, I should specify my problem a little bit... so here is an image of my plot. I think lollipop plot wouldn't work, cause it's a stacked barplot. In short I have 3 columns, the first is a character column with for example the names of manufacturers (it's the x axis in the plot and there are 149 manufacturer). The second column (character) contains the specific productnames for the respective manufacturer (25 products per manfacturer, so there are columns with length 149*25) . And the third column (numeric) represents the quality of the products (y axis). I want to split the 149 manufacturers into equal parts ( 50, 50, 49). At the end I want 3 diagrams instead of one with 149 bars...

If your data are in a data frame named DF, a sketch of the code using ggplot for plotting could be like the following.

library(dplyr)
library(ggplot2)
Companies <- unique(DF$Company)
Grp1 <- Companies[1:50]
Grp2 <- Companies[51:100]
Grp3 <- Companies[101:149]

DF <- DF %>% mutate(Grp = case_when(
  Company %in% Grp1 ~ 1,
  Company %in% Grp2 ~ 2,
  Company %in% Grp3 ~ 3,
)) 

ggplot(DF, aes(...)) + geom_col() +
  facet_wrap(~Grp)

Thank you, I'll try this. And do you have an idea for a more universal code? For example if I have 213 (or another number) manufacturers?

Best regards, Paula

Just out of curiosity, can you tell us what this plot is supposed to communicate? Even with the arbitrary split in equal sized chunks I fail to see a practical purpose, if you want to highlight fail rate distribution of the products I think a ridge plot would be more useful and if your intention is to compare manufacturers maybe some aggregation like a pareto chart would be better.

1 Like

Here is a simple way to form groups of 50.

Companies <- unique(DF$Company)
Grp <- 0:(length(Companies) - 1) %/% 50
names(Grp) <- Companies
DF$Grp <- Grp[DF$Company]

@andresrcs You're having good ideas, thank you. So let me explain it in detail. As you can see, the barplot is stacked. The single parts of a bar represent different tests for failure mechanisms. The barplot tells me which test has the most impact and so we can infer failures in the products. With 149 bars I can't see the distribution of the colored parts very clear.

Nice, looks good. I'll try it. Thanks in advance!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.