0

reproducible example:

x1<-rnorm(5,5,1)
y1<-rnorm(5,5,1)
d<-data.frame(x1,y1)

ggplot(data=d,aes(x=x1,y=y1))+
  geom_point()+
  ylab(bquote('y (since year s'* ~ 1^st*' day)'))

I would like to add an apostrophe after "year" and I tried to add '\\'' but it does not work.

There are already several questions asking about superscript:

Subscripts and superscripts "-" or "+" with ggplot2 axis labels? (ionic chemical notation)

How to write chemical formulas in ggplot

ggplot labels adding superscript, how to come out of the superscript?

But I could not find any that combines it with an apostrophe (which is recognized by the superscript expression).

DAme
  • 697
  • 8
  • 21
have fun
  • 381
  • 5
  • 17

1 Answers1

2

Single quotes ' and double quotes " are usually interchangeable in R code. Get the single quote you want by surrounding the string containing it with double quotes.

library(ggplot2)
x1<-rnorm(5,5,1)
y1<-rnorm(5,5,1)
d<-data.frame(x1,y1)

ggplot(data=d,aes(x=x1,y=y1))+
  geom_point()+
  ylab(bquote("y (since year's"* ~ 1^st*' day)'))

Created on 2021-01-02 by the reprex package (v0.3.0)

mrhellmann
  • 5,069
  • 11
  • 38
  • Thanks, that was easy. I had tried but I must have messed up something else and thought it would not work. – have fun Jan 02 '21 at 13:50