0

I am plotting a grouped bar chart for the following sample dataset.

  Group Age
1  G1    29
2  G2    25
3  G3    55
4  G2    33
5  G1    70
6  G3    80

In my plot, each group has some Age range and I am using the following syntax.

df<- mutate(df, Age_class = cut(LPA_CN, breaks = c(0, 20, 30, 35, 40, 80))) 

However, the legend in the plot shows (0,20], (20,30], (30, 35], (35, 40] and (40, 80]. Is there a way to make it (0,20) (21,30) (30, 35) (35, 40) and (40, 80) ?

BeginneR
  • 69
  • 7

1 Answers1

1

For that you would need to provide your custom labels to cut -

library(dplyr)

df <- mutate(df, Age_class = cut(LPA_CN, breaks = c(0, 20, 30, 35, 40, 80), 
                labels = c('(0,20)', '(21,30)', '(30, 35)', '(35, 40)', '(40, 80)'))) 
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213