0

I need to subcript the letter T (with an e) in the following text:

"In/Out RZ Te = 400s"

In Latex I would do $T_{e}$. I need the same but in R.

I need to add the value to a cell in a dataframe

user20650
  • 24,654
  • 5
  • 56
  • 91
BlueMountain
  • 197
  • 2
  • 17
  • is this in a plot / document / or? but likely you want to red `?plotmath` (hint: `~T[e]`) – user20650 Jan 25 '20 at 13:29
  • I need to add the value to a cell in a dataframe. – BlueMountain Jan 25 '20 at 14:12
  • okay. To what aim please? This is fairly non-standard as outputs in the terminal are generally plain text. You can use subscripts in tables outputs to html, tex, and figures etc which would be a more standard way to present results. But its not impossible, you could use unicode (`data.frame(x="T\U2091")`) but I'd think this is not very flexible / going to cause problems down the line – user20650 Jan 25 '20 at 14:19
  • afterwards these cells will be the text in the strips of a gglplot facet_grid – BlueMountain Jan 25 '20 at 14:26
  • btw, when I do print(x="T\U2091") It does not work. For instance, x="T\U2122" works. – BlueMountain Jan 25 '20 at 14:27
  • ah okay. So if you are wanting to use in plots a more standard way is to use `expression`'s like in the first comment. This can have slightly nicer formatting and be more flexible. There are many examples in SO of using subscripts in ggplot facet labels – user20650 Jan 25 '20 at 14:29
  • https://stackoverflow.com/questions/28316214/how-to-apply-subscript-in-the-facet-grid-function-of-ggplot may be useful – user20650 Jan 25 '20 at 14:36
  • ... e.g. `d = data.frame(x=1, y=1, z="'In/Out RZ'*~T[e]== '400s'", stringsAsFactors = FALSE) ; ggplot(d, aes(x,y)) + facet_wrap(~z, labeller=label_parsed)` – user20650 Jan 25 '20 at 14:38
  • but I'm using facet_grid, not facet_wrap – BlueMountain Jan 25 '20 at 15:08
  • did you try the example, changing facet_wrap to facet_grid (and tweaking the facet function) – user20650 Jan 25 '20 at 15:11
  • Yes, that is what I tried but you can very nicely see the subscript with facet_wrap and not with facet_grid. – BlueMountain Jan 25 '20 at 15:14
  • `ggplot(d, aes(x,y)) + facet_grid(~z, labeller=label_parsed)` and `ggplot(d, aes(x,y)) + facet_grid(.~z, labeller=label_parsed)` produce similar results for me. – user20650 Jan 25 '20 at 15:15
  • If you continue to have difficulties I recommend you ask a new question giving a reproducible example – user20650 Jan 25 '20 at 15:16
  • how would you do it with an extra column? Let's say "'In/Out RZ'*~T[e]== '400s'" and "'In/Out RZ'*~T[e]== '600s'". Maybe that is closer to my case. – BlueMountain Jan 25 '20 at 15:21
  • 1
    You just need to create an expression for each facet. I tend to dind it easier to create a vector of facet labels outside of the data data.frame and pass this to the ggplot functions. An example, `d = data.frame(x=1:2, y=1:2, z=1:2); lbs = c('1'="'In/Out RZ'*~T[e]== '400s'", '2'="'In/Out RZ'*~T[e]== '600s'") ; ggplot(d, aes(x,y)) + facet_grid(.~z, labeller=as_labeller(lbs, label_parsed))` (of course if your facet variable is coded as `400, 600` etc you could use `bquote` to automate constructing the expressions) – user20650 Jan 25 '20 at 15:35
  • Thank you verye much but still not working, the only thing different now between your plot and mine is that I also have variables on the right side of the plot, meaning facet_grid(something~z). – BlueMountain Jan 25 '20 at 16:14
  • It worked, thanks. Would you also know how to add a line break after "RZ"? The text is too long for a single line. – BlueMountain Jan 27 '20 at 13:53
  • 1
    one way is to use `atop` e.g. `lbs = c('1'="atop('In/Out RZ',T[e]== '400s')", '2'="'In/Out RZ'*~T[e]== '600s'")`. See`?plotmath` for details. – user20650 Jan 27 '20 at 14:02

0 Answers0