cataclysmic
cataclysmic

Reputation: 187

multiple logic symbols "<" "<=" in ggplot label

I would like to label discrete axis values in a ggplot barchart with maths expressions. These expression indicate intervals which is why I need multiple "<" and "<=" in my label.

When trying to produce these labels using R "expression" I get an "unexpected symbol" error. Below is the code that I have that produces the error. When removing the 2nd condition everything works fine.

group_name = c(expression(0 <= g[i] < 5),
           expression(5 <= g[i] <= 15),
           expression(15 < g[i] <= 20))

The above list is then assigned to scale_x_discrete().

Upvotes: 4

Views: 176

Answers (1)

Roland
Roland

Reputation: 132959

Use {}:

plot.new()
text(0.5, 0.5, label = expression({0 <= g[i]} < 5), cex = 5)

resulting plot

Upvotes: 6

Related Questions