Janak Janak - 1 year ago 59
R Question

Adding greek symbol (pi) on the axis tick mark of a plot

I want to print the greek alphabet (multiple of) pi in the x-label tick mark of a histogram in R.
Specifically, let us consider the example:

x=runif(100,0,pi)
hist(x,freq = F)


enter image description here

Now how to print actual expression of (0,pi/7,pi/6,pi/5,pi/4,pi/3,pi/2,pi)
at the x axis tick mark instead of (0,0.5,1,1.5,2,2.5,3,3.5) in the above plot?

Answer Source

I understand, that with "label" you actually mean "tick mark". Otherwise see the answer given by ira. You may want to change the at= part to something more appropriate.

x=runif(100,0,pi)
hist(x, xaxt="n")
axis(side=3, at=c(0,0.5,1,1.5,2,2.5,3,3.5),
     labels=c("0","pi/7","pi/6","pi/5","pi/4","pi/3","pi/2","pi"))
axis(side=1, at=c(0,0.5,1,1.5,2,2.5,3,3.5),
     labels=c("0",expression(pi/7),expression(pi/6),expression(pi/5),
          expression(pi/4),expression(pi/3),expression(pi/2),
          expression(pi)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download