I am sorry but I think I have been unclear.   The problem is not color
theme.  Assume I have the original data.frame.

testdf <- structure(list(yy = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("R", "L"), class = c("ordered",
"factor")),
                         xx = c(8L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 32L,
33L, 34L, 37L, 38L, 44L, 47L, 48L),
                         zz = c(-0.0509470162236187, -0.127284016213917,
-0.148955671035087, -0.142907338502986, -0.160948815798959,
-0.173350477727937, -0.161083124553469,
                             -0.14273409035068, -0.0214438692797626,
-0.0628618704957434, -0.0877747107755074, -0.0948371137126557,
-0.0659475583478307, -0.0601482978919971,
                             -0.0339547824620206, -0.0433516197870341)),
                    .Names = c("yy", "xx", "zz"),
                    row.names = c("25", "26", "27", "28", "29", "210",
"211", "212", "213", "214", "215", "216", "217", "218", "219", "220"),
class = "data.frame")

Based on Duncan's suggestion, I modify it as

testdf$y <- ifelse(testdf$yy == "L",1,0)

If you look at the 'testdf' data.frame

> head(testdf)

      yy xx          zz        y
25   R  8 -0.05094702 0
26   R 44 -0.12728402 0
27   R 45 -0.14895567 0
28   R 46 -0.14290734 0
29   R 47 -0.16094882 0
210  R 48 -0.17335048 0

there is only one value for xx = 8 and all the remaining values are between
32 to 50

> sort(testdf$xx)
 [1]  8 32 33 34 37 38 44 44 45 46 47 47 48 48 49 50


However, when I use levelplot for the modified 'testdf' as suggested by
Duncan

 testcol <- c("#FF0000","#00FF00","#0000FF","#FFA54F",
             "#00FFFF","#FF00FF","#C00000","#00B414")

levelplot(zz~ xx+y, testdf,
            at =  seq(-0.2,0, 0.025),
            cuts = 8,
            col.regions = testcol,
             xlim = c(0, 50),
             colorkey = list(labels = paste(seq(-0.2,0, 0.025)),
                             at =  seq(-0.2,0, 0.025),
                             cex = 1.5)
            )

I see a 'pink' box from xx = 0 to 20 (for y = 0) and a 'green' box from xx
= 20 to 32 (for y=1). These boxes should not be there because there are no
xx's in (8, 32).  This probably happens because there is only one xx = 8
and all the remaining xx's are >=32.  If I remove xx = 8 from the plot by
using 'subset = xx > 8', then everything appears as it should.  That is why
I had used xlim = c(0, 50).

levelplot(zz~ xx+y, testdf, subset = xx > 8,
            at =  seq(-0.2,0, 0.025),
            cuts = 8,
            col.regions = testcol,
             xlim = c(0, 50),
             colorkey = list(labels = paste(seq(-0.2,0, 0.025)),
                             at =  seq(-0.2,0, 0.025),
                             cex = 1.5)
            )

This is problem might be due to my 'pathological' data set.  If yes, then
is there a lattice-y way to get around it?  If levelplot is the wrong
function for such needs, then please accept my sincere apologies.

Thanks for your patience.

Best,
S.


On Mon, Jul 7, 2014 at 12:42 AM, Duncan Mackay <dulca...@bigpond.com> wrote:

> Your y values are not of the type required by levelplot
> ? levelplot
>
> I prefer not to use themes as they do not suit my data here is a way to get
> what you want - colours are a bit garish but they are some easily to hand
> breaks/cuts are just what came in a reasonable sequence - yours to change
>
> testdf$y <- ifelse(testdf$yy == "L",1,0)
>
> levelplot(zz ~ xx + y, testdf, par.settings = custom.theme.2(),
>           scales = list(x = list(cex = 0.5, rot=90), y = list(cex = 0.5),
>                          alternating = FALSE),
>           xlim = c(0, 50),
>           at = seq(-0.3, 0.3, length = 20),
>           panel = function(x, y, z, ...) {
>               panel.levelplot(x, y, z,...)
>           },
>           colorkey=list(labels = list(cex = 1.5))
>           )
>
>   testcol <- c("#FF0000","#00FF00","#0000FF","#FFA54F",
>              "#00FFFF","#FF00FF","#C00000","#00B414")
>
>   levelplot(zz~ xx+y, testdf,#subset(testdf, xx > 0),
>             at =  seq(-0.2,0, 0.025),
>             cuts = 8,
>             col.regions = testcol,
>             scales = list(x = list(cex = 0.5,
>                                    rot = 90),
>                           y = list(cex = 0.5),
>                           alternating = FALSE),
>              xlim = c(0, 50),
>              colorkey = list(labels = paste(seq(-0.2,0, 0.025)),
>                              at =  seq(-0.2,0, 0.025),
>                              cex = 1.5)
>             )
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
>
> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On
> Behalf Of Sunny Srivastava
> Sent: Monday, 7 July 2014 09:35
> To: R mailing list
> Subject: [R] Question regarding lattice::levelplot and distribution of
> colors
>
> Hello R-helpers:
>
> I think there is some problem with my code, but I would like to seek you
> help because I can't spot it.
>
> I have a data.frame defined as follows:
>
> testdf <- structure(list(yy = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("R", "L"), class = c("ordered",
> "factor")),
>                          xx = c(8L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 32L,
> 33L, 34L, 37L, 38L, 44L, 47L, 48L),
>                          zz = c(-0.0509470162236187, -0.127284016213917,
> -0.148955671035087, -0.142907338502986, -0.160948815798959,
> -0.173350477727937, -0.161083124553469,
>                              -0.14273409035068, -0.0214438692797626,
> -0.0628618704957434, -0.0877747107755074, -0.0948371137126557,
> -0.0659475583478307, -0.0601482978919971,
>                              -0.0339547824620206, -0.0433516197870341)),
>                     .Names = c("yy", "xx", "zz"),
>                     row.names = c("25", "26", "27", "28", "29", "210",
> "211", "212", "213", "214", "215", "216", "217", "218", "219", "220"),
> class = "data.frame")
>
> I would like to see a 'levelplot'  of yy vs xx, but the value of xx creates
> problem in the distribution of colors.  I am guessing it is due to the
> value of xx = 8.  The levelplot below seems to be fine.
>
> library(latticeExtra)
>
>
> ## ok; note the subset argument!
> levelplot(zz ~ xx + yy, testdf, par.settings = custom.theme.2(), subset =
> xx != 8,
>           scales = list(x = list(cex = 0.5, rot=90), y = list(cex = 0.5),
> alternating = FALSE),
>           xlim = c(0, 50),
>           at = seq(-0.3, 0.3, length = 20),
>           panel = function(x, y, z, ...) {
>               panel.levelplot(x, y, z,...)
>           },
>           colorkey=list(labels = list(cex = 1.5))
>           )
>
> If I remove the subsetting of xx != 8, then the distribution of colors is
> wrong.  Specifically, it ranges from xx =1 to 20 for y = R, which is
> incorrect.  What am I missing here?  Note that using the default color
> scheme has no effect.
>
> ## seems to be a bug ? see xx = 1 to 20; note that the subset argument is
> removed
> levelplot(zz ~ xx + yy, testdf, par.settings = custom.theme.2(),
>           scales = list(x = list(cex = 0.5, rot=90), y = list(cex = 0.5),
> alternating = FALSE),
>           xlim = c(0, 50),
>           at = seq(-0.3, 0.3, length = 20),
>           panel = function(x, y, z, ...) {
>               panel.levelplot(x, y, z,...)
>           },
>           colorkey=list(labels = list(cex = 1.5))
>           )
>
>
> Thanks,
> S.
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to