[R] levelplot help needed

Antje niederlein-rstat at yahoo.de
Fri Feb 27 14:51:38 CET 2009


Hi there,

I'm looking for someone who can give me some hints how to make a nice 
levelplot. As an example, I have the following code:

# create some example data
# --------------------------------------
xl <- 4
yl <- 10

my.data <- sapply(1:xl, FUN = function(x) { rnorm( yl, mean = x) })

x_label <- rep(c("X Label 1", "X Label 2", "X Label 3", "X Label 4"), each = yl)
y_label <- rep(paste("Y Label ", 1:yl, sep=""), xl)

df <- data.frame(x_label = factor(x_label),y_label = factor(y_label), values = 
as.vector(my.data))

df1 <- data.frame(df, group = rep("Group 1", xl*yl))
df2 <- data.frame(df, group = rep("Group 2", xl*yl))
df3 <- data.frame(df, group = rep("Group 3", xl*yl))

mdf <- rbind(df1,df2,df3)

# plot
# --------------------------------------

graph <- levelplot(mdf$values ~ mdf$x_label * mdf$y_label | mdf$group,
				aspect = "xy", layout = c(3,1),
				scales = list(x = list(labels = substr(levels(factor(mdf$x_label)),0,5), 
rot = 45)))
             print(graph)

# --------------------------------------


(I need to put this strange x-labels, because in my real data the values of the 
x-labels are too long and I just want to display the first 10 characters as label)

My questions:

* I'd like to start with "Y Label 1" in the upper row (that's a more general 
issue, how can I have influence on the order of x,y, and groups?)
* I'd like to put the groups at the bottom

Can anybody give me some help?

Antje




More information about the R-help mailing list