[R] Lattice: Customizing point-sizes with groups
Paul C. Boutros
Paul.Boutros at utoronto.ca
Tue Mar 10 17:21:38 CET 2009
Yup, that would be my work-around.
I was hoping for a cleaner way of doing this, though, because I am
calculating cex based on other properties of the data-points, so that it
becomes a continuous variable.
-----Original Message-----
From: Sundar Dorai-Raj [mailto:sdorairaj at gmail.com]
Sent: Tuesday, March 10, 2009 12:01 PM
To: Paul C. Boutros
Cc: r-help at r-project.org
Subject: Re: [R] Lattice: Customizing point-sizes with groups
Sorry, I missed your point the first time. Why not create a group for
each subset then?
xyplot(y ~ x, temp, groups = interaction(cex, groups),
par.settings = list(
superpose.symbol = list(
cex = c(1, 2, 3, 4),
pch = 19,
col = c("blue", "red", "green", "purple"))))
On Tue, Mar 10, 2009 at 8:11 AM, Paul C. Boutros
<Paul.Boutros at utoronto.ca> wrote:
> Hi Sundar,
>
> Thanks for your help! Unfortunately your code seems to give the same
> result. Compare this:
>
> temp <- data.frame(
> x = 1:10,
> y = 1:10,
> cex = rep( c(1,3), 5),
> col = c( rep("blue", 5), rep("red", 5) ),
> groups = c( rep("A", 5), rep("B", 5) )
> );
>
> xyplot(y ~ x, temp, groups = groups,
> par.settings = list(
> superpose.symbol = list(
> cex = c(1, 3),
> pch = 19,
> col = c("blue", "red"))))
>
> And this:
> xyplot(y ~ x, temp, cex = temp$cex, col = temp$col, pch = 19);
>
> Once I introduce groups, I lose the ability to customize individual
> data-points and seem only to be able to customize entire groups.
>
> Paul
>
> -----Original Message-----
> From: Sundar Dorai-Raj [mailto:sdorairaj at gmail.com]
> Sent: Tuesday, March 10, 2009 5:49 AM
> To: Paul.Boutros at utoronto.ca
> Cc: r-help at r-project.org
> Subject: Re: [R] Lattice: Customizing point-sizes with groups
>
> Try this:
>
> xyplot(y ~ x, temp, groups = groups,
> par.settings = list(
> superpose.symbol = list(
> cex = c(1, 3),
> pch = 19,
> col = c("blue", "red"))))
>
> See:
>
> str(trellis.par.get())
>
> for other settings you might want to change.
>
> Also, you should drop the ";" from all your scripts.
>
> HTH,
>
> --sundar
>
> On Mon, Mar 9, 2009 at 6:49 PM, Paul Boutros <paul.boutros at utoronto.ca>
> wrote:
>> Hello,
>>
>> I am creating a scatter-plot in lattice, and I would like to customize
the
>> size of each point so that some points are larger and others smaller.
>> Here's a toy example:
>>
>> library(lattice);
>>
>> temp <- data.frame(
>> x = 1:10,
>> y = 1:10,
>> cex = rep( c(1,3), 5),
>> groups = c( rep("A", 5), rep("B", 5) )
>> );
>>
>> xyplot(y ~ x, temp, cex = temp$cex, pch = 19);
>>
>> This works just fine if I create a straight xy-plot, without groups.
>> However when I introduce groupings the cex argument specifies the
>> point-size for the entire group. For example:
>>
>> xyplot(y ~ x, temp, cex = temp$cex, pch = 19, group = groups);
>>
>> Is it possible to combine per-spot sizing with groups in some way? One
>> work-around is to manually specify all graphical parameters, but I
thought
>> there might be a better way than this:
>>
>> temp$col <- rep("blue", 10);
>> temp$col[temp$groups == "B"] <- "red";
>> xyplot(y ~ x, temp, cex = temp$cex, pch = 19, col = temp$col);
>>
>> Any suggestions/advice is much appreciated!
>> Paul
>>
>> ______________________________________________
>> 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