[R] Superscript and subscrib R for legend x-axis and y-axis and colour different subjects in longitudinal data with different colours
Bert Gunter
bgunter.4567 at gmail.com
Fri Jul 28 18:09:50 CEST 2017
1. Why all the library calls to ggplot and lattice if you are using
only basic graphics?
2. Note that:
sub = mtext(expression(paste(lambda)))
is not the same as your
sub = "lambda = 0.7"
Not sure why you think it is.
In any case, you need to learn about R's "plotmath" capabilities for
constructing mathematical annotation in plot labelling. See ?plotmath.
Better yet, as this is complex and rather difficult, do a web search
for "R plotmath tutorials" (perhaps in rseek.org) to get you started.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Fri, Jul 28, 2017 at 8:07 AM, Rosa Oliveira <rosita21 at gmail.com> wrote:
> I am trying to make a x-axis and y-axis titles with both a special character and a subscript. I am not being able to do this. I think its just a placing of my parenthesis, but I've tried (seemingly) everything.
>
> Even more, when I try the blog users code it works.
>
>
>
> Is it because I’m using longitudinal data?
>
>
>
> Even more. Is it possible to colour each one of the 15 lines with a different colour?
>
>
>
>
>
>
> library(ggplot2)
> library(reshape)
> library(lattice)
> library(gtable)
> library(grid)
>
> attach(mtcars)
>
> beta0 = rnorm (15, 1, .5)
> beta1 = rnorm (15, -1, .5)
>
> tempo = seq(1:5)
>
> CRP7raw = matrix(NA, 15, 5)
> CRP7 = matrix(NA, 15, 5)
> CRP98raw = matrix(NA, 15, 5)
> CRP98 = matrix(NA, 15, 5)
>
> crp <- for (i in 1:15) {
> CRP7raw[i,] = beta0[i] + beta1[i] * tempo
> CRP7[i,] = CRP7raw[i,] + rnorm(5, 0, 2.14)
>
> CRP98raw[i,] = beta0[i] + beta1[i] * tempo
> CRP98[i,] = CRP98raw[i,] + rnorm(5, 0, .1)
> }
>
>
> # plot(c(1:5), CRP7raw[1,], type = "n", xlim=c(1,5), ylim=c(-10,5) ,
> # xlab="Day in ICU",
> # ylab="CRP (mg/dL)",
> # sub = mtext(expression(paste(lambda)))
> #
> # CRP7graph <- apply(CRP7, 1, lines, col="gray")
>
>
>
>
>
>
> # plot(c(1:5), CRP98raw[1,], type = "n", xlim=c(1,5), ylim=c(-10,5),
> # xlab="Day in ICU",
> # ylab="CRP (mg/dL)")
> # CRP98graph <- apply(CRP98, 1, lines, col="gray")
>
> par(mfrow=c(1,2))
>
> plot(c(1:5), CRP7raw[1,], type = "n", xlim=c(1,5), ylim=c(-10,5) ,
> xlab="t_i",
> ylab="y_ij",
> sub = "lambda = 0.7")
>
> CRP7graph <- apply(CRP7, 1, lines, col="gray")
>
>
> plot(c(1:5), CRP98raw[1,], type = "n", xlim=c(1,5), ylim=c(-10,5),
> xlab="Day in ICU",
> ylab="CRP (mg/dL",
> sub = "lambda = 0.98")
> CRP98graph <- apply(CRP98, 1, lines, col="gray")
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list