Search code examples
rggplot2axis-labels

Why this R ggplot subscript is not working?


Code where trying to apply g + labs(y=expression(N_{s})) with the following error which does not make sense

g <- ggplot(datm, aes(variable, value, fill=gender)) + geom_bar(stat="identity", position = position_dodge()) + facet_grid(male.Nij ~ group) + xlab("Association type") + ggtitle("View")
#http://stackoverflow.com/a/17335258/54964
g + labs( y=expression(N_{s}) )

I get

Error: unexpected '{' in "g + labs( y=expression(N_{"
Execution halted

R: 3.3.2 backports
OS: Debian 8.5


Solution

  • it it not {}

    # if you want to use sbuscript, use []
    p + labs( y=expression(N[s]) )
    # or as is
    p + labs( y=expression(N_~'{s}') )