[R] Multi-line texts in plots
baptiste auguie
ba208 at exeter.ac.uk
Fri Mar 20 12:56:37 CET 2009
Hi,
it would help if you provided a minimal example.
Here is one approach I often use with the plotting package ggplot2,
parameters <- expand.grid(m=c(0, 1), s=seq(0.1, 1,length=10))
x <- seq(-5, 5, length=300)
foo <- function(m, s){
data.frame(x=x, y=dnorm(x, m, s), m=factor(m), s=factor(s))
}
# construct a data.frame with all the data
results <- do.call(rbind, mapply(foo, m=parameters$m, s=parameters$s,
SIMPLIFY=F))
library(ggplot2)
p1 <- qplot(x, y, data=results, geom="line", colour=s, linetype=m)
p2 <- p1 + facet_grid(m~.)
results2 <- within(results, f <- factor(paste("m=", m,"; s=", s)))
p3 <- qplot(x, y, data=results2, geom="line", colour=f)
p1 # note how the legend is constructed for you
p2 # clearest imho
p3 # with 20 levels it's not very readable
Hope this helps,
baptiste
On 20 Mar 2009, at 10:59, mauede at alice.it wrote:
> I am running a simulation many times changing one parameter each
> time and recording the outcome.
> I have to produce a plot to make a sense of the bunch of numbers I
> get from every run.
> My problem is to insert a multi-line text to keep track of which
> result correspond to which parameter values.
> A legend does not work in this case because I will plot 2 variables
> and the corresponding experimental values.
> So two curves on the same drawing as a result of the combination of
> 20 parameters.
> I may decide to place two plots on the same canvas but if so I will
> have to find the space for two 20-line texts ....
> In short, I wonder how I can insert a 20-line text on each plot. I
> browsed through the documentation of the par command
> but I could not find any helpful option.
> Thank you in advance for any suggestion.
> Maura
>
>
> tutti i telefonini TIM!
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
_____________________________
Baptiste Auguié
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
Phone: +44 1392 264187
http://newton.ex.ac.uk/research/emag
More information about the R-help
mailing list