Home > Blockchain >  is there a way to rename the range name in y-axis in chart?
is there a way to rename the range name in y-axis in chart?

Time:11-03

rank <- as.numeric(rank)
rank[is.na(rank)] <- 0

scale_y_reverse(breaks = 0:28)


enter image description here

that's now the result i have but i want it to become 'new' 0 1 2 3 ... as shown:

enter image description here

it has a few 'new' to the rank. therefore I changed it to be numeric format and then the 'new' become NA. however I want to show it then I make it NA to be 0. but now I want the 0 in the plot to become a 'new' word.

CodePudding user response:

You can use the labels argument to replace() the first value:

library(ggplot2)

ggplot()   
  aes(y = 0:10)  
  scale_y_reverse(breaks = 0:10, labels = ~ replace(.x, 1, "New")) 

enter image description here

  • Related