4

Consider this example:

labs <- c("AT~frac(T,C)~G","GGAA","TTAA","AAAA")
plot(c(1:4), c(1:4), axes=F, xlab="",ylab="", par(mar=c(8,3,2,1)))
axis(1, at=c(1:4), labels=labs, las=2)

that generates this:

enter image description here

My intention is to have something like this:

enter image description here

that I hardcoded as:

plot(c(1:4), c(1:4), type="n", axes=F, xlab="",ylab="")
axis(1, at=c(1:4), labels=c(expression(AT~frac(T,C)~G), expression(GGAA), expression(TTAA), expression(AAAA)), las=2)

The closest answer I got was this. Getting expression() to work as I desired is really very confusing for me. I intend to have these x-axis tick mark labels dynamically generated from available data using a vector of "expression strings".

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

3

You were close! frac() is a function that you need to call. it can be used with strings as an argument. This sample

labs <- expression(paste("AT"~frac("T","C")~"G",sep=""),"GGAA","TTAA","AAAA")
plot(c(1:4), c(1:4), axes=F, xlab="",ylab="")
axis(1, at=c(1:4), labels=labs, las=2)

generates this plot:

labels

David Go
  • 810
  • 1
  • 7
  • 13