How do I keep top 10 shops in the chart and label/bucket the rest under others.
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.
# make ranking # min_rank() gives ranks in ascending order, so adjust to reverse # rank (n()+1) - min_rank(sum_dep_delay)
# 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)
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='_')
I hope this helps.
Amazing, thank you so much for your prompt feedback!