1

I cannot add subscripts nor superscripts in my code, because Expression function is needed.

My PC is windows 10, Rstudio Version 1.1.383 and R version 3.4.3.

The message I recived is this when I used the function.

expression("v") expression("v")

I have no warning signal, expression prints itself with the arguments.

I need help, I need this codes for publication.

I tried even with Unicode. I am trying to write log10 (10 as subscript)

paste0("Log ","\u2081","\u2080") 

In addition to this problem, this computer is new, and I have to read csv as csv2. I do not why!

Help!

  • 2
    What did you try? Please provide some example code like `plot(1:1, main=expression('hi'[5]*'there'[6]^8*'you'[2]))` (from here: https://stackoverflow.com/questions/10156417/subscripts-in-plots-in-r) – Robert Hijmans Dec 20 '17 at 03:56

1 Answers1

3

You don't give any sample data, nor do you provide your code, so it's difficult to troubleshoot. Here is an example using expression in ggplot.

require(ggplot2);
ggplot(data.frame(x = seq(1:10), y = seq(1:10)), aes(x = x, y = y)) +
    geom_point() +
    labs(x = expression('log' [10] * '(10' ^x * ')'))

enter image description here


Update

As pointed out by @42-, the quotes are not needed:

require(ggplot2);
ggplot(data.frame(x = seq(1:10), y = seq(1:10)), aes(x = x, y = y)) +
    geom_point() +
    labs(x = expression(log[10](10^x)))
Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • I was not using it appropiately, I see. – Jose Victor Zambrana Dec 20 '17 at 04:17
  • The problem was that this symbol("") was damaging my code. When I do it with your (' ') it worked. I have used this function befores, but this time was not working – Jose Victor Zambrana Dec 20 '17 at 04:22
  • @JoseVictorZambrana Yes, in my opinion, constructing `expression`s can be a bit troublesome (and trial and error) sometimes. Above expression also works with double quotes `"..."` instead of single quotes `'...'`, so that's not the problem. Perhaps you didn't concatenate strings and expressions with `*`? – Maurits Evers Dec 20 '17 at 04:28
  • when I run in the console: expression('log' [10] *' titer'), shows up the same thing expression("log"[10] * " titer"). But when I linked with ggplot, it appears as subscript – Jose Victor Zambrana Dec 20 '17 at 05:03
  • @JoseVictorZambrana I'm confused. What did you expect to happen when you enter `expression('log' [10] *' titer')` in an R terminal? As per `?expression`, it returns a vector of type `expression`. – Maurits Evers Dec 20 '17 at 05:56
  • The quotes should not be needed. – IRTFM Dec 20 '17 at 07:10
  • @42- Thanks, I've added an update. – Maurits Evers Dec 20 '17 at 07:16