I have 2 data sets. In data, b is encoded as numeric values. data1 represents the original in which b is chr data.
I would like to plot a box plot using the numeric data from data but pull the y-axis tick labels from the chr data b in data1. Is this possible?
Toy data:
data <- data.frame(a = c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3),
b = c(10,10,11,11,12,12,12,13,13,13,14,14,14,15,15),
c = c('x','y','y','x','y','y','x','y','y','x','y','y','x','x','y'))
data1 <- data.frame(a = c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3),
b = c('never','never','rare','rare','some','some','some','most','most','most','often','often','often','always','always'),
c = c('x','y','y','x','y','y','x','y','y','x','y','y','x','x','y'))
My attempt to achieve the outcome using scale_y_discrete:
ggplot(data,aes(x = as.factor(a), y = b, fill = c))+
geom_boxplot()+
scale_y_discrete(data1$b,labels=unique(data1$b))
As you can see, the y-axis tick labels are not displaying as anticipated.
For further reference, this is to be used on a far larger data set as part of a Shiny application. The plot forms a reactive element and so I need to avoid hard-coding the actual label names.
Your help is appreciated.

