Exploratory Community

Show top 10 list and rest under others


How do I keep top 10 shops in the chart and label/bucket the rest under others.

Much appreciated!


Hello @Mahmoud_Issa

The settings are probably not available from the chart UI. Therefore, you may need to process the data before creating the chart. There are several ways to do this. I suggest one solution as shown below.

The final chart image is arranged in the order of the top 10, with “Others” appearing at the end of the bar chart even if the aggregate value is larger than the top 10.

step01 : Aggregate the value


step02 : Make ranking

# make ranking
# min_rank() gives ranks in ascending order, so adjust to reverse

# rank
(n()+1) - min_rank(sum_dep_delay)

step03 : Modify rank & name

# for grouping and labeling together in `other`.

# is_top10_name
if_else(rank <= 10, name, 'other')
# is_top10_rank
if_else(rank <= 10, rank, 11)

step04 : Concatenate modified rank and name

You can use the factor class to control the order, but if the aggregate value of other is larger than the Top 10, it will be troublesome to adjust the order, so here we directly control the order of the characters.

# controll the Order of Charts

# is_top10
str_c(str_pad(is_top10_rank, pad='0', width=2L), is_top10_name, sep='_')

step05 : Make chart

I hope this helps.


Amazing, thank you so much for your prompt feedback!

1 Like