0

I am creating a line chart in ggplot2 with a continuous y-axis but I would like to change the labels to strings to represent bounds, is this possible? For example, I want all values V<10 = A, 10>V<20 = B, and V>20 = C.

Y<-c(5,15,12,8,12,13,19,24)
Day<-c(1,2,3,4,5,6,7,8)
data <- data.frame(Y, Day)
ggplot(data= data, aes(x=Day, y=Y, group=1))+geom_line()+geom_point()

The label of 10 would be replaced by A, 20 by B and so on.

Hope this is a little clearer, thank you.

Olli
  • 65
  • 3
  • 4
    Hi Olli, yes, it's possible, but your description of what you want isn't clear enough to allow for a demonstration. Could you edit your question to give a minimal reproducible example, including a sample of your data, your current code, and a clearer description of what you want your plot to look like? – Allan Cameron Jul 12 '20 at 20:34
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 12 '20 at 22:04
  • Apologies, I have now updated the question. Many thanks. – Olli Jul 13 '20 at 07:55

1 Answers1

2

You can use scale_y_continuous and relabel the scale using the labels= argument. The key here is to also use breaks= which map back to the original numeric scale and then I'm also using limits= to ensure that we can see the whole alphabet.

ggplot(data= data, aes(x=Day, y=Y, group=1))+geom_line()+geom_point() +
  scale_y_continuous(labels=LETTERS, breaks=1:26, limits=c(1,26))

enter image description here

chemdork123
  • 10,461
  • 1
  • 14
  • 29