Skip to content
Prev 174327 / 398506 Next

Multi-line texts in plots

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:

            
_____________________________

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