2

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.

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? Commented Jul 12, 2020 at 20:34
  • 1
    It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. Commented Jul 12, 2020 at 22:04
  • Apologies, I have now updated the question. Many thanks. Commented Jul 13, 2020 at 7:55

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.