bvowe
bvowe

Reputation: 3384

GGplot add "word" to y axis label

Sample data

library(ggplot2)
ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot()

My attempt

ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot() + ylab(len == 10, "ten")

Here the goal is to replace '10' on the y-axis with "ten"

Upvotes: 2

Views: 402

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24252

If you need to replace on the y-axis only the value 10 with "Ten", you can use this solution:

library(databases)
library(ggplot2)

ggplot(ToothGrowth, aes(x=dose, y=len, group=1)) + geom_boxplot() +
       scale_y_continuous(label=function(x) ifelse(x==10,"Ten",x))

enter image description here

Upvotes: 1

Related Questions