An expression containing a comma as an annotation on one face: is this possible?

I am interested in building a custom expression containing a comma on one face of the graph in ggplot2. I know how to build expressions on one face using a new data frame as follows:

fakedata <- data.frame(x = 1:10, y=runif(10), grp=gl(2,5))

ggplot(fakedata, aes(x=x,y,y)) + geom_point() + facet_grid(. ~ grp) +
   geom_text(data=data.frame(x=5,y=0.5,grp=1,lab='a == 5'), aes(label=lab), parse=TRUE)

expression on one face

I also know how to build expressions on multiple faces using annotation_custom, which can hold a semicolon expression. But this cannot be done on one side only.

ggplot(fakedata, aes(x=x,y,y)) + geom_point() + facet_grid(. ~ grp) +
   annotation_custom(grobTree(textGrob(expression(paste(a == 5, ', ', b == 6)), x=.5, y=.5)))

semicolon expression on both sides

But I can’t understand what to do for a semicolon expression on the same face, since you cannot store previously defined expressions in a data frame. How can I build a semicolon expression on the same face?

+4
source share
1 answer

?plotmath list():

'list (x, y, z): ,

g0 + geom_text(data=data.frame(x=5,y=0.5,grp=1,lab='list(a == 5, b==6)'),
      aes(label=lab), parse=TRUE)
+5

Source: https://habr.com/ru/post/1627523/


All Articles