[R] [FORGED] Re: single strip for the same group in dotplot lattice

Paul Murrell paul at stat.auckland.ac.nz
Fri Feb 24 02:26:45 CET 2017


Hi

The following is a bit customised to your example, but maybe if there's 
no other way ...

library(grid)
## Go down to the viewport that lays everything out
downViewport("plot_01.toplevel.vp")
## Eyeball the widths and heights (the "null"s are the plot regions)
## current.viewport()$layout$widths
## current.viewport()$layout$heights
## Make a viewport along the top strips and draw in it
pushViewport(viewport(layout.pos.col=7:25,
                       layout.pos.row=8))
grid.rect(y=1, height=unit(1, "lines"), just="top",
           gp=gpar(fill="paleturquoise"))
grid.text("run_2", y=unit(1, "npc") - unit(.5, "lines"))
upViewport()
## Make a viewport along the bottom strips and draw in it
pushViewport(viewport(layout.pos.col=7:25,
                       layout.pos.row=12))
grid.rect(y=1, height=unit(1, "lines"), just="top",
           gp=gpar(fill="paleturquoise"))
grid.text("run_1", y=unit(1, "npc") - unit(.5, "lines"))
upViewport()

Paul

On 23/02/17 22:00, Luigi Marongiu wrote:
> Dear Duncan and Philip,
> thank you for your answers. maybe the toy data I gave it is a bit too easy,
> so I am attaching a new dataset with 5 targets. As you can see from it, now
> there are 5 panel strips with the label "run_1" and 5 with the label
> "run_2". What I would like to do is to merge those with the same label so
> to have only two labels "run_1" and "run_2".
> the examples from Duncan contains plenty of keys but I think make the
> reading of the plot more difficult; most of the plots have only one strip.
> thank you
> luigi
>
>>>>
> # the values are actually repeated, but they are just for example
> cluster <- c(rep("run_1", 45), rep("run_2", 45))
> type <- rep(c("blank", "positive", "negative"),30)
> target <- rep(c(rep("A", 3), rep("B", 3), rep("C", 3), rep("D", 3),
> rep("E", 3)), 6)
> value <- rep(c(rnorm(1, mean=0.001, sd=0.1), rnorm(1, mean=2, sd=1),
> rnorm(1, mean=1, sd=1)),30)
> my.data <- data.frame(cluster, type, target, value)
>
> library(lattice)
> dotplot(
>   value ~ type|target + cluster,
>   my.data,
>   groups = type,
>   pch=21,
>   main = "Luminex analysis MTb humans",
>   xlab = "Target", ylab = "Reading",
>   col = c("grey", "green", "red"),
>   par.settings = list(strip.background = list(col="paleturquoise")),
>   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
>   key = list(
>     space = "top",
>     columns = 3,
>     text = list(c("Blank", "Negative", "Positive"), col="black"),
>     rectangles = list(col=c("grey", "green", "red"))
>   )
> )
>
>
> On Thu, Feb 23, 2017 at 2:50 AM, Duncan Mackay <dulcalma at bigpond.com> wrote:
>
>> Hi Liugi
>>
>> Here are some ideas quickly
>>
>> 4 panels diagonals are blank
>>
>> mdata = my.data
>> mdata$ct <- paste(target, "Run", rep(1:2, each = 6))
>> mdata$typeT <- paste(mdata$target,mdata$type)
>>
>> dotplot(
>>   value ~ type|ct,
>>   mdata2,
>>   groups = typeT,
>>   par.settings = list(strip.background = list(col="paleturquoise"),
>>                       superpose.symbol = list(col = c(2:4),
>>                                               pch = rep(c(1,20),each =
>> 3))),
>> # type
>>   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
>>   main = "Luminex analysis MTb humans",
>>   xlab = "Target",
>>   ylab = "Reading",
>>   auto.key = T,
>>   panel = panel.superpose
>> )
>>
>> # for when the 4 panels have plots not 2 as now
>>  mdata2 = mdata
>>  mdata2$target = rep(LETTERS[2:1], ea=6)
>>  mdata2$value= mdata2$value+0.1
>>  mdata2 <- rbind(mdata,mdata2)
>>
>> mdata2$typeT <- paste(mdata2$target,mdata2$type)
>>
>>  dotplot(
>>    value ~ type|target + cluster,
>>    mdata2,
>>    groups = typeT,
>>    par.settings = list(strip.background = list(col="paleturquoise"),
>>                        superpose.symbol = list(col = c(2:4),
>>                                                pch = rep(c(1,20),each =
>> 3))), # type
>>    scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
>>    main = "Luminex analysis MTb humans",
>>    xlab = "Target",
>>    ylab = "Reading",
>>    auto.key = T,
>>    panel = panel.superpose
>>  )
>>
>>
>>  dotplot(
>>    value ~ type|ct,
>>    mdata2,
>>    groups = typeT,
>>    par.settings = list(strip.background = list(col="paleturquoise"),
>>                        superpose.symbol = list(col = c(2:4),
>>                                                pch = rep(c(1,20),each =
>> 3))), # type
>>    scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
>>    main = "Luminex analysis MTb humans",
>>    strip    = strip.custom(factor.levels = paste("Run",1:2),
>>                         par.strip.text = list(cex = 1) ),
>>    xlab = "Target",
>>    ylab = "Reading",
>>    auto.key = T,
>>    panel = panel.superpose
>>  )
>>
>> dotplot(
>>   value ~ type|cluster,
>>   mdata2,
>>   groups = typeT,
>>   par.settings = list(strip.background = list(col="paleturquoise"),
>>                       superpose.symbol = list(col = c(2:4),
>>                                               pch = rep(c(1,20),each =
>> 3))),
>> # type
>>   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
>>   main = "Luminex analysis MTb humans",
>>   xlab = "Target",
>>   ylab = "Reading",
>>   auto.key = T,
>>   panel = panel.superpose
>> )
>>
>>
>> Regards
>>
>> Duncan
>>
>> -----Original Message-----
>> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi
>> Marongiu
>> Sent: Wednesday, 22 February 2017 21:26
>> To: P Tennant; r-help
>> Subject: Re: [R] single strip for the same group in dotplot lattice
>>
>> Dear Philip,
>> the data is indeed a toy data: the real one will have 15 panels (=targets)
>> and two or three clusters. this means that I will have 15 strips with the
>> label "run 1" = "cluster 1" etc. the point of the toy data is that I get a
>> 4x4 panel plot with 8 strips labelled "run 1", "run 2", "A" and "B". What I
>> am looking for is to collapse the strips so to get only one label "run 1"
>> and only one with "run 2" in order to simplify the plot. Hope this helps.
>> Thanks
>> Luigi
>>
>> On Wed, Feb 22, 2017 at 9:53 AM, P Tennant <philipt900 at iinet.net.au>
>> wrote:
>>
>>> Hi Luigi,
>>>
>>> I'm afraid I don't understand your toy data as you've described it, but
>> if
>>> you really don't have run 2 for target A, and don't have run 1 for target
>>> B, why not just create another factor that reflects this, and plot that?
>>>
>>>  my.data$clus2 <- with(my.data, interaction(cluster, target))
>>>
>>>  and call: dotplot(value ~ type| clus2, ... )
>>>
>>>
>>> Philip
>>>
>>>
>>> On 22/02/2017 8:03 PM, Luigi Marongiu wrote:
>>>
>>>> dear all,
>>>> I have a set of data that is subdivided in cluster (run 1/run 2) and in
>>>> target (A/B). When plotting, I obtain a panel strip with "run 1" and
>> "run
>>>> 2" for each "A" and "B" panel, so "run 1" appears twice and so does "run
>>>> 2". It is possible to merge the strip together so that I will have "run
>> 1"
>>>> or "run 2" only once? this will reduce the complexity of the data and
>>>> allow
>>>> more space for more detailed information in the strip.
>>>> the data follows,
>>>> thank you
>>>> L
>>>>
>>>> cluster<- c(rep("run_1", 6), rep("run_2", 6))
>>>> type<- rep(c("blank", "positive", "negative"),2)
>>>> target<- c(rep("A", 6), rep("B", 6))
>>>> value<- c(0.01, 1.1, 0.5,
>>>>             0.02, 1.6, 0.8,
>>>>             0.07, 1.4, 0.7,
>>>>             0.03, 1.4, 0.4)
>>>> my.data<- data.frame(cluster, type, target, value)
>>>>
>>>> library(lattice)
>>>> dotplot(
>>>>    value ~ type|target + cluster,
>>>>    my.data,
>>>>    groups = type,
>>>>    pch=21,
>>>>    main = "Luminex analysis MTb humans",
>>>>    xlab = "Target", ylab = "Reading",
>>>>    col = c("grey", "green", "red"),
>>>>    par.settings = list(strip.background = list(col="paleturquoise")),
>>>>    scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
>>>>    key = list(
>>>>      space = "top",
>>>>      columns = 3,
>>>>      text = list(c("Blank", "Negative", "Positive"), col="black"),
>>>>      rectangles = list(col=c("grey", "green", "red"))
>>>>    )
>>>> )
>>>>
>>>>         [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>>> ng-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>>
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list