[R] Lattice : Help with changing the labels of x-axis in respective panels

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Dec 4 10:37:11 CET 2009


On Fri, Dec 4, 2009 at 11:53 AM, Sunny Srivastava
<research.baba at gmail.com> wrote:
> Dear R-Helpers,
> I am not very experienced in using lattice and I am still in the learning
> stage
>
> I have a data set which looks like this: (I have deleted a few lines in
> order to save space)
>
>   Chromosome marker Marker.Name Distance
> 1           1      1     PeMm261   0.0000
> 2           1      2       Xtxp8  10.1013
> ..
> 20          1     20     EbMi148 210.3099
> 21          1     21      Xtxp25 232.0118
> 22          2      1     EcMm152   0.0000
> 23          2      2     EeMp342   5.1474
> ...
> 36          2     15     EaMp217 124.5115
> 37          2     16     EaMp131 136.9033
> ....
> 40          3      1    TEak2908   0.0000
> 41          3      2     Xtxp303   4.7094
> 42          3      3     EhMm195  10.1694
>
> (I have 11 chromosome in total .. so conditioning on chromosome gives me 11
> panels)
>
> This is a data.frame which contains Chromosome Number, Marker Number for
> that chromosome and the corresponding Marker.Name and Distance.
>
> I want to plot the genetic distance conditioned on chromosome and the marker
> name listed below the distance where the marker is situated on chromosome
> (something like this picture)
>
> Panel 1 : Chromosome 1
>
> |-------------------|-------------------------  (so and so forth)
> PeMm261     Xtxp8
> <---- 10.1013 ->  (the distance b/w these markers is same as the
> corresponding value in marker$Distance - see 1 and 2 row in the sample
> output)
>
> and similarly for other chromosomes.

Here's one attempt; hopefully it will give you useful ideas:


df <-
structure(list(Chromosome = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
3L, 3L, 3L), marker = c(1L, 2L, 20L, 21L, 1L, 2L, 15L, 16L, 1L,
2L, 3L), Marker.Name = structure(c(7L, 11L, 3L, 9L, 4L, 5L, 2L,
1L, 8L, 10L, 6L), .Label = c("EaMp131", "EaMp217", "EbMi148",
"EcMm152", "EeMp342", "EhMm195", "PeMm261", "TEak2908", "Xtxp25",
"Xtxp303", "Xtxp8"), class = "factor"), Distance = c(0, 10.1013,
210.3099, 232.0118, 0, 5.1474, 124.5115, 136.9033, 0, 4.7094,
10.1694)), .Names = c("Chromosome", "marker", "Marker.Name",
"Distance"), class = "data.frame", row.names = c("1", "2", "20",
"21", "22", "23", "36", "37", "40", "41", "42"))


library(lattice)

## single panel
dotplot(Chromosome ~ Distance, df, mnames = df$Marker.Name,
        panel = function(x, y, ..., mnames, subscripts) {
            panel.dotplot(x, y, ...)
            panel.text(x, y, labels = mnames[subscripts],
                       srt = 90, adj = -0.1)
        })

## multiple panels
dotplot( ~ Distance | factor(Chromosome), df, mnames = df$Marker.Name,
        layout = c(1, 3), strip = FALSE, strip.left = TRUE,
        panel = function(x, y, ..., mnames, subscripts) {
            panel.dotplot(x, y, ...)
            panel.text(x, y, labels = mnames[subscripts],
                       srt = 90, adj = -0.1)
        })

-Deepayan

>
>
> I tried:
>
> plt1 = dotplot(  ~ Distance | Chromosome, data=marker,par.strip.text =
> list(cex = 0.75), layout = c(1,11),
>        lattice.options=list(legend="right"), xlab="Distance in cM",
> ylab="",
>        scales= list(cex=0.5),
>
>        panel = function(x, y) {
>           panel.grid(h=1,v= 345)
>           panel.xyplot(x, y,pch=20,type="o",lwd="2",cex=1.5)
>       },
> )
>
> update(plt1, main="Genetic Map",
>  strip = strip.custom(factor.levels = c("1",
> "2","3","4","5","6","7","8","9","10","11"), strip.levels = TRUE))
>
>
> This gives me the location of markers on the respective chromosomes
> corresponding to the distances in the above data.frame. The markers are just
> shown as points.
>
>
> MY QUESTIONS - 1) If I want to label these dots with the corresponding
> marker names - How do I do that?
>                             2) Is there a way in lattice - to know which
> panel I am in.
>
> I tried inserting panel.text in the panel function - but it doesn't like
> that. (I also played around with scales - but without any success)
>
> Any help will be greatly appreciated.
>
> Thx,
> S.
>
> -------------------------------------------------------------------------------
>> sessionInfo()
> R version 2.9.1 (2009-06-26)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] lattice_0.17-25 qtl_1.14-2
>
> loaded via a namespace (and not attached):
> [1] grid_2.9.1  tools_2.9.1
>
>        [[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.
>




More information about the R-help mailing list