[R] high density plots using lattice dotplot()

Duncan Mackay dulcalma at bigpond.com
Thu Apr 23 16:26:25 CEST 2015


Hi Luigi

Michael answered your question about printing 

lattice and ggplot require their graphics to be in print()

If you have problems in printing you may have to use 

trellis.device(device = pdf,  # or what ever the actual device is
                        file = ####,
                        <remainder of script>)
? trellis.device for info
I occasionally have to use it sometimes instead of pdf etc

Duncan

-----Original Message-----
From: Luigi Marongiu [mailto:marongiu.luigi at gmail.com] 
Sent: Thursday, 23 April 2015 22:56
To: Duncan Mackay
Subject: Re: [R] high density plots using lattice dotplot()

Dear Duncan,
many thanks for the precious help! I have rearranged what you sent me
with a bit of stuff I wrote already for another project and the
results seems to work fine.
Best regards,
Luigi

>>> example
DF <-
  data.frame(Y = rnorm(17280),
             X = rnorm(1:45),
             Y2 = rnorm(17280)+2,
             Z  = 1:384)
head(df,10)
xyplot(Y ~ X | Z,
       data = DF,
       groups = Z,
       allow.multiple = TRUE,
       ylab= "Y VALUES",
       xlab="X VALUES",
       main="TITLE",
       scales = list(
         x = list(draw = FALSE),
         y = list(draw = FALSE),
         relation="same",
         alternating=TRUE),
       as.table = TRUE,
       layout = c(24,16),
       par.settings = list(
         strip.background=list(col="white"),
         axis.text = list(cex = 0.6),
         par.xlab.text = list(cex = 0.75),
         par.ylab.text = list(cex = 0.75),
         par.main.text = list(cex = 0.8),
         superpose.symbol = list(type = "l", cex = 1)
       ),
       strip    = FALSE,
       type = "l",
       col = 3,
       panel = panel.superpose
)

On Thu, Apr 23, 2015 at 3:08 AM, Duncan Mackay <dulcalma at bigpond.com> wrote:
> Hi Luigi
>
> Try
>
> set.seed(1)
>
> PLATE <-
> data.frame(Delta.Rn = rnorm(500),
>            Cycle = rnorm(500),
>            Delta2 = rnorm(500)+1,
>            Well  = rep(1:50, each = 10))
> head(PLATE,10)
>
> xyplot(Delta.Rn+Delta2 ~ Cycle | Well,
>          data = subset(PLATE, Well %in% 1:49),
>          allow.multiple = TRUE,
>          ylab="Fluorescence (Delta Rn)",
>          xlab="Cycles",
>          main="TITLE",
>          scales = list(
>            x = list(draw = FALSE),
>            y = list(draw = FALSE),
>            relation="same",
>            alternating=TRUE),
>          as.table = TRUE,
>          layout = c(10,5),
>          par.settings = list(
>            strip.background=list(col="white"),
>            # layout.heights = list(strip = 0.8),
>            axis.text = list(cex = 0.6),
>            par.xlab.text = list(cex = 0.75),
>            par.ylab.text = list(cex = 0.75),
>            par.main.text = list(cex = 0.8),
>            superpose.symbol = list(pch = ".", cex = 2,
>                                    col = c(2,4) )
>          ),
>          strip    = FALSE,
>          type = "p",
>          key = list(text = list(label = c("Delta.Rn","Delta2")),
>                     points = list(cex = 0.6, pch = 16, col = c(2,4)),
>                     cex = 0.6,
>                     x = 0.9,
>                     y = 0.1),
>          panel = panel.superpose,
>          panel.groups = function(x,y,...){
>
>                    panel.xyplot(x,y,... )
>
>                    # text argument can be a vector of values not
>                    # necessarily the group name
>                    pnl = panel.number()  # needed as group.number if added is now either 1 or 2
>
>                    grid.text(c(LETTERS,letters)[pnl],
>                              y = 0.93, x = 0.5,
>                              default.units = "npc",
>                              just = c("left", "bottom"),
>                              gp = gpar(fontsize = 7) )
>
>          }
>   )
>
> Remember to delete the group argument (I forgot to at first as the groups are now Delta.Rn Delta2)
> You may have 1+ empty panels so put the legend there where ever it is just amend the x and y or fine tune them
> you can have the pch = "." and increase cex but  it will become as square with large cex
> Duncan
>
>
> -----Original Message-----
> From: Luigi Marongiu [mailto:marongiu.luigi at gmail.com]
> Sent: Thursday, 23 April 2015 10:05
> To: Duncan Mackay
> Subject: Re: [R] high density plots using lattice dotplot()
>
> Dear Duncan,
> sorry to come back so soon, but i wanted to ask you whether it would
> be  possible to plot two sets of lines within each box, let's say a
> main value A and a secondary value B. In normal plots I could use a
> plot() followed by points(); what would be the strategy here?
> Thank you again,
> best regards,
> Luigi
>
>
> On Wed, Apr 22, 2015 at 6:46 AM, Duncan Mackay <dulcalma at bigpond.com> wrote:
>>
>> Hi Luigi
>>
>> I should have made up an example to make things easier when I replied today
>>
>> This should get you going
>>
>> set.seed(1)
>>
>> PLATE <-
>> data.frame(Delta.Rn = rnorm(500),
>>            Cycle = rnorm(500),
>>            Well  = rep(1:50, each = 10))
>> head(PLATE)
>>
>> xyplot(Delta.Rn ~ Cycle | Well,
>>          data = PLATE,
>>          groups = Well,
>>          ylab="Fluorescence (Delta Rn)",
>>          xlab="Cycles",
>>          main="TITLE",
>>          scales = list(
>>            x = list(draw = FALSE),
>>            y = list(draw = FALSE),
>>            relation="same",
>>            alternating=TRUE),
>>          as.table = TRUE,
>>          layout = c(10,5),
>>          par.settings = list(
>>            strip.background=list(col="white"),
>>            # layout.heights = list(strip = 0.8),
>>            axis.text = list(cex = 0.6),
>>            par.xlab.text = list(cex = 0.75),
>>            par.ylab.text = list(cex = 0.75),
>>           par.main.text = list(cex = 0.8)
>>            superpose.symbol = list(pch = ".", cex = 2)
>>          ),
>>          strip    = FALSE,
>>          type = "p",
>>          col = 1,
>>          panel = panel.superpose,
>>          panel.groups = function(x,y,...,group.number){
>>
>>                    panel.xyplot(x,y,... )
>>
>>                    # text argument can be a vector of values not
>>                    # necessarily the group name
>>                    grid.text(c(LETTERS,letters)[group.number],
>>                              y = 0.93, x = 0.5,
>>                              default.units = "npc",
>>                              just = c("left", "bottom"),
>>                              gp = gpar(fontsize = 7) )
>>
>>          }
>>   )
>>
>> You could use panel.text instead of grid.text
>> Duncan
>>
>> -----Original Message-----
>> From: Luigi Marongiu [mailto:marongiu.luigi at gmail.com]
>> Sent: Wednesday, 22 April 2015 08:24
>> To: Duncan Mackay
>> Subject: Re: [R] high density plots using lattice dotplot()
>>
>> Dear Duncan,
>> thank you for your reply. I tried to implement your suggestions but as
>> is on your reply did not work (actually R crashed) and a slight
>> elaboration returned the figure attached, which is essentially still
>> displaying text and not drawing the data. Here is what I wrote:
>>
>> xyplot(Delta.Rn ~ Cycle | Well,
>>          data = PLATE,
>>          ylab="Fluorescence (Delta Rn)",
>>          xlab="Cycles",
>>          main=TITLE,
>>          scales = list(
>>            x = list(draw = FALSE),
>>            y = list(draw = FALSE),
>>            relation="same",
>>            alternating=TRUE),
>>          as.table = TRUE,
>>          layout = c(24,16),
>>          par.settings = list(
>>            strip.background=list(col="white"),
>>            axis.text = list(cex = 0.6),
>>            par.xlab.text = list(cex = 0.75),
>>            par.ylab.text = list(cex = 0.75),
>>            superpose.symbol = list(pch = ".", cex = 2)
>>          ),
>>          strip    = FALSE,
>>          type = "p",
>>          layout.heights = list(strip = 0.8),
>>          panel = function(x,y, subscripts, groups,...){
>>            panel.superpose(x,y,subscripts,groups,...,
>>                            col = ...)
>>            panel.text(x,y,...,cex = 0.6)
>>          }
>>   )
>>
>>
>> How can I improve the script?
>> Many thanks
>> Luigi
>>
>> On Tue, Apr 21, 2015 at 12:35 AM, Duncan Mackay <dulcalma at bigpond.com> wrote:
>>> Hi Luigi
>>>
>>> Strips take up space so if you are willing to not have strip and put the
>>> strip values within the plot area then
>>>
>>>       xyplot(y ~ x|cond.factor, data = ...,
>>>              as.table = T,
>>>              groups   = ...,
>>>              layout   = ...,
>>>              drop.unused = T,
>>>              par.settings = list(axis.text = list(cex = 0.6),
>>>                                  par.xlab.text = list(cex = 0.75),
>>>                                  par.ylab.text = list(cex = 0.75)
>>>                                  superpose.symbol = list(pch = ".", cex = 2)
>>>                             ),
>>>              strip    = FALSE,
>>>              scales   = list(x = list(alternating = 2),
>>>                              y = list(alternating = FALSE)
>>>                              ),
>>>              type = "p",
>>>              panel = function(x,y, subscripts, groups,...){
>>>                                 panel.superpose(x,y,subscripts,groups,...,
>>> col = ...)
>>>                                 panel.text(x,y,...,cex = 0.6)
>>>                             }
>>>       )
>>>
>>> if the text values are a vector
>>>       stext = ...
>>>       xyplot(y ~ x|cond.factor, data = ...,
>>>              as.table = T,
>>>              groups   = ...,
>>>              layout   = ...,
>>>              drop.unused = T,
>>>              par.settings = list(axis.text = list(cex = 0.6),
>>>                                  par.xlab.text = list(cex = 0.75),
>>>                                  par.ylab.text = list(cex = 0.75)
>>>                                  superpose.symbol = list(pch = ".", cex = 2)
>>>                             ),
>>>              strip    = FALSE,
>>>              scales   = list(x = list(alternating = 2),
>>>                              y = list(alternating = FALSE)
>>>                              ),
>>>              type = "p",
>>>              panel = function(x,y, subscripts, groups,...){
>>>                                pnl = panel.number()
>>>                                 panel.superpose(x,y,subscripts,groups,...,
>>> col = ...)
>>>                                 panel.text(x,y,stext[pnl],cex = 0.6)
>>>                             }
>>>       )
>>>
>>> you could also you group.number instead of pnl if it is needed elsewhere.
>>> text position could be done in a similar fashion if needed to be in
>>> different places for some panels.
>>>
>>> If you require the strip then an additional par.settings is
>>> layout.heights = list(strip = 0.8)
>>> or even untested in this situation
>>> strip = FALSE
>>> strip.left  = TRUE
>>>
>>> Regards
>>>
>>> Duncan
>>>
>>> Duncan Mackay
>>> Department of Agronomy and Soil Science
>>> University of New England
>>> Armidale NSW 2351
>>> Email: home: mackay at northnet.com.au
>>>
>>> -----Original Message-----
>>> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi
>>> Marongiu
>>> Sent: Sunday, 19 April 2015 19:28
>>> To: r-help
>>> Subject: [R] high density plots using lattice dotplot()
>>>
>>> Dear all,
>>> I am trying to plot the results of a PCR experiments that involves 384
>>> individual plots. Admittedly the space for the plots will be tiny, but
>>> I just nedd some icon to have a feeling of the layout of the
>>> experiment and a quick comparison of the plots.
>>> I believe that lattice would be the right tool, but when I tried to
>>> implement i got an error. Specifically the output would be a A4 pdf,
>>> so with about 600 cm2 of drawing space, which gives about 1.5 cm2 for
>>> each plot; removing the labels that might just work.
>>> So I have the y values = 'fluorescence', x 'values' = cycles and 384
>>> 'well' data. I implemented to begin with:
>>>
>>> xyplot(fluorescence ~ cycles | well,
>>>          ylab="Fluorescence",
>>>          xlab="Cycles",
>>>          main=list(draw = FALSE),
>>>          scales = list(
>>>            x = list(draw = FALSE),
>>>            y = list(draw = FALSE),
>>>            relation="same",
>>>            alternating=TRUE),
>>>          layout = c(24,16),
>>>          par.settings = list(strip.background=list(col="white")),
>>>          pch = "."
>>>   )
>>>
>>> but the  the individual graphs show only the writing "data" instead of
>>> the actual plots.
>>> How can I overcome this error?
>>> Thank you
>>> Best regards
>>> Luigi
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>



More information about the R-help mailing list