[R] levelplot help needed

Sundar Dorai-Raj sdorairaj at gmail.com
Fri Feb 27 18:07:21 CET 2009


To reorder the y-labels, simply reorder the factor levels:

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

Not sure about putting the strips at the bottom. A quick scan of
?xyplot and ?strip.default suggests that this is not possible, but I'm
sure Deepayan will correct me if I'm wrong (he often does).

--sundar

On Fri, Feb 27, 2009 at 5:51 AM, Antje <niederlein-rstat at yahoo.de> wrote:
> 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
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list