Define pch and color based on two different columns

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Define pch and color based on two different columns

msnyder424
I am making a lattice plot and I would like to use the value in one column
to define the pch and another column to define color of points. Something
like:

xyplot(mpg ~ wt | cyl,
       data=mtcars,
       col = gear,
       pch = carb
)

There are unique pch points in the second and third panels, but these
points are only unique within the plots, not among all the plots (as they
should be). You can see this if you use the following code:

xyplot(mpg ~ wt | cyl,
       data=mtcars,
       groups = carb
)

This plot looks great for one group, but if you try to invoke two groups
using c(gear, carb) I think it simply takes unique combinations of those
two variables and plots them as unique colors.

Another solution given by a StackExchange user:

mypch <- 1:6
mycol <- 1:3

xyplot(mpg ~ wt | cyl,
          panel = function(x, y, ..., groups, subscripts) {
              pch <- mypch[factor(carb[subscripts])]
              col <- mycol[factor(gear[subscripts])]
              grp <- c(gear,carb)
              panel.xyplot(x, y, pch = pch, col = col)
          }
)

This solution has the same problems as the code at the top. I think the
issue causing problems with both solutions is that not every value for each
group is present in each panel, and they are almost never in the same
order. I think R is just interpreting the appearance of unique values as a
signal to change to the next pch or color. My actual data file is very
large, and it's not possible to sort my way out of this mess. It would be
best if I could just use the value in two columns to actually define a
color or pch for each point on an entire plot. Is there a way to do this?

Ps, I had to post this via email because the Nabble site kept sending me an
error message: "Message rejected by filter rule match"

Thanks,
Matt



*Matthew R. Snyder*
*~~~~~~~~~~~~~~~~~*
PhD Candidate
University Fellow
University of Toledo
Computational biologist, ecologist, and bioinformatician
Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
[hidden email]
[hidden email]



[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
04/09/19,
1:49:27 PM

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

Jim Lemon-4
Hi Matthew,
How about this?

library(lattice)
xyplot(mpg ~ wt | cyl,
       data=mtcars,
       col = mtcars$gear,
       pch = mtcars$carb
)
library(plotrix)
grange<-range(mtcars$gear)
xyplot(mpg ~ wt | cyl,
       data=mtcars,
       col = color.scale(mtcars$gear,extremes=c("blue","red"),xrange=grange),
       pch = as.character(mtcars$carb)
)

Jim

On Wed, Apr 10, 2019 at 7:43 AM Matthew Snyder <[hidden email]> wrote:

>
> I am making a lattice plot and I would like to use the value in one column
> to define the pch and another column to define color of points. Something
> like:
>
> xyplot(mpg ~ wt | cyl,
>        data=mtcars,
>        col = gear,
>        pch = carb
> )
>
> There are unique pch points in the second and third panels, but these
> points are only unique within the plots, not among all the plots (as they
> should be). You can see this if you use the following code:
>
> xyplot(mpg ~ wt | cyl,
>        data=mtcars,
>        groups = carb
> )
>
> This plot looks great for one group, but if you try to invoke two groups
> using c(gear, carb) I think it simply takes unique combinations of those
> two variables and plots them as unique colors.
>
> Another solution given by a StackExchange user:
>
> mypch <- 1:6
> mycol <- 1:3
>
> xyplot(mpg ~ wt | cyl,
>           panel = function(x, y, ..., groups, subscripts) {
>               pch <- mypch[factor(carb[subscripts])]
>               col <- mycol[factor(gear[subscripts])]
>               grp <- c(gear,carb)
>               panel.xyplot(x, y, pch = pch, col = col)
>           }
> )
>
> This solution has the same problems as the code at the top. I think the
> issue causing problems with both solutions is that not every value for each
> group is present in each panel, and they are almost never in the same
> order. I think R is just interpreting the appearance of unique values as a
> signal to change to the next pch or color. My actual data file is very
> large, and it's not possible to sort my way out of this mess. It would be
> best if I could just use the value in two columns to actually define a
> color or pch for each point on an entire plot. Is there a way to do this?
>
> Ps, I had to post this via email because the Nabble site kept sending me an
> error message: "Message rejected by filter rule match"
>
> Thanks,
> Matt
>
>
>
> *Matthew R. Snyder*
> *~~~~~~~~~~~~~~~~~*
> PhD Candidate
> University Fellow
> University of Toledo
> Computational biologist, ecologist, and bioinformatician
> Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> [hidden email]
> [hidden email]
>
>
>
> [image: Mailtrack]
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
> Sender
> notified by
> Mailtrack
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
> 04/09/19,
> 1:49:27 PM
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

msnyder424
Thanks, Jim.

I appreciate your contributed answer, but neither of those make the desired
plot either. I'm actually kind of shocked this isn't an easier more
straightforward thing. It seems like this would be something that a user
would want to do frequently. I can actually do this for single plots in
ggplot. Maybe I should contact the authors of lattice and see if this is
something they can help me with or if they would like to add this as a
feature in the future...

Matt



*Matthew R. Snyder*
*~~~~~~~~~~~~~~~~~*
PhD Candidate
University Fellow
University of Toledo
Computational biologist, ecologist, and bioinformatician
Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
[hidden email]
[hidden email]



[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
04/09/19,
7:52:27 PM

On Tue, Apr 9, 2019 at 4:53 PM Jim Lemon <[hidden email]> wrote:

> Hi Matthew,
> How about this?
>
> library(lattice)
> xyplot(mpg ~ wt | cyl,
>        data=mtcars,
>        col = mtcars$gear,
>        pch = mtcars$carb
> )
> library(plotrix)
> grange<-range(mtcars$gear)
> xyplot(mpg ~ wt | cyl,
>        data=mtcars,
>        col =
> color.scale(mtcars$gear,extremes=c("blue","red"),xrange=grange),
>        pch = as.character(mtcars$carb)
> )
>
> Jim
>
> On Wed, Apr 10, 2019 at 7:43 AM Matthew Snyder <[hidden email]>
> wrote:
> >
> > I am making a lattice plot and I would like to use the value in one
> column
> > to define the pch and another column to define color of points. Something
> > like:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        col = gear,
> >        pch = carb
> > )
> >
> > There are unique pch points in the second and third panels, but these
> > points are only unique within the plots, not among all the plots (as they
> > should be). You can see this if you use the following code:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        groups = carb
> > )
> >
> > This plot looks great for one group, but if you try to invoke two groups
> > using c(gear, carb) I think it simply takes unique combinations of those
> > two variables and plots them as unique colors.
> >
> > Another solution given by a StackExchange user:
> >
> > mypch <- 1:6
> > mycol <- 1:3
> >
> > xyplot(mpg ~ wt | cyl,
> >           panel = function(x, y, ..., groups, subscripts) {
> >               pch <- mypch[factor(carb[subscripts])]
> >               col <- mycol[factor(gear[subscripts])]
> >               grp <- c(gear,carb)
> >               panel.xyplot(x, y, pch = pch, col = col)
> >           }
> > )
> >
> > This solution has the same problems as the code at the top. I think the
> > issue causing problems with both solutions is that not every value for
> each
> > group is present in each panel, and they are almost never in the same
> > order. I think R is just interpreting the appearance of unique values as
> a
> > signal to change to the next pch or color. My actual data file is very
> > large, and it's not possible to sort my way out of this mess. It would be
> > best if I could just use the value in two columns to actually define a
> > color or pch for each point on an entire plot. Is there a way to do this?
> >
> > Ps, I had to post this via email because the Nabble site kept sending me
> an
> > error message: "Message rejected by filter rule match"
> >
> > Thanks,
> > Matt
> >
> >
> >
> > *Matthew R. Snyder*
> > *~~~~~~~~~~~~~~~~~*
> > PhD Candidate
> > University Fellow
> > University of Toledo
> > Computational biologist, ecologist, and bioinformatician
> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > [hidden email]
> > [hidden email]
> >
> >
> >
> > [image: Mailtrack]
> > <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> > Sender
> > notified by
> > Mailtrack
> > <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> > 04/09/19,
> > 1:49:27 PM
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

Jeff Newmiller
Maybe you should use factors rather than character columns.

On April 9, 2019 8:09:43 PM PDT, Matthew Snyder <[hidden email]> wrote:

>Thanks, Jim.
>
>I appreciate your contributed answer, but neither of those make the
>desired
>plot either. I'm actually kind of shocked this isn't an easier more
>straightforward thing. It seems like this would be something that a
>user
>would want to do frequently. I can actually do this for single plots in
>ggplot. Maybe I should contact the authors of lattice and see if this
>is
>something they can help me with or if they would like to add this as a
>feature in the future...
>
>Matt
>
>
>
>*Matthew R. Snyder*
>*~~~~~~~~~~~~~~~~~*
>PhD Candidate
>University Fellow
>University of Toledo
>Computational biologist, ecologist, and bioinformatician
>Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
>[hidden email]
>[hidden email]
>
>
>
>[image: Mailtrack]
><https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
>Sender
>notified by
>Mailtrack
><https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
>04/09/19,
>7:52:27 PM
>
>On Tue, Apr 9, 2019 at 4:53 PM Jim Lemon <[hidden email]> wrote:
>
>> Hi Matthew,
>> How about this?
>>
>> library(lattice)
>> xyplot(mpg ~ wt | cyl,
>>        data=mtcars,
>>        col = mtcars$gear,
>>        pch = mtcars$carb
>> )
>> library(plotrix)
>> grange<-range(mtcars$gear)
>> xyplot(mpg ~ wt | cyl,
>>        data=mtcars,
>>        col =
>> color.scale(mtcars$gear,extremes=c("blue","red"),xrange=grange),
>>        pch = as.character(mtcars$carb)
>> )
>>
>> Jim
>>
>> On Wed, Apr 10, 2019 at 7:43 AM Matthew Snyder <[hidden email]>
>> wrote:
>> >
>> > I am making a lattice plot and I would like to use the value in one
>> column
>> > to define the pch and another column to define color of points.
>Something
>> > like:
>> >
>> > xyplot(mpg ~ wt | cyl,
>> >        data=mtcars,
>> >        col = gear,
>> >        pch = carb
>> > )
>> >
>> > There are unique pch points in the second and third panels, but
>these
>> > points are only unique within the plots, not among all the plots
>(as they
>> > should be). You can see this if you use the following code:
>> >
>> > xyplot(mpg ~ wt | cyl,
>> >        data=mtcars,
>> >        groups = carb
>> > )
>> >
>> > This plot looks great for one group, but if you try to invoke two
>groups
>> > using c(gear, carb) I think it simply takes unique combinations of
>those
>> > two variables and plots them as unique colors.
>> >
>> > Another solution given by a StackExchange user:
>> >
>> > mypch <- 1:6
>> > mycol <- 1:3
>> >
>> > xyplot(mpg ~ wt | cyl,
>> >           panel = function(x, y, ..., groups, subscripts) {
>> >               pch <- mypch[factor(carb[subscripts])]
>> >               col <- mycol[factor(gear[subscripts])]
>> >               grp <- c(gear,carb)
>> >               panel.xyplot(x, y, pch = pch, col = col)
>> >           }
>> > )
>> >
>> > This solution has the same problems as the code at the top. I think
>the
>> > issue causing problems with both solutions is that not every value
>for
>> each
>> > group is present in each panel, and they are almost never in the
>same
>> > order. I think R is just interpreting the appearance of unique
>values as
>> a
>> > signal to change to the next pch or color. My actual data file is
>very
>> > large, and it's not possible to sort my way out of this mess. It
>would be
>> > best if I could just use the value in two columns to actually
>define a
>> > color or pch for each point on an entire plot. Is there a way to do
>this?
>> >
>> > Ps, I had to post this via email because the Nabble site kept
>sending me
>> an
>> > error message: "Message rejected by filter rule match"
>> >
>> > Thanks,
>> > Matt
>> >
>> >
>> >
>> > *Matthew R. Snyder*
>> > *~~~~~~~~~~~~~~~~~*
>> > PhD Candidate
>> > University Fellow
>> > University of Toledo
>> > Computational biologist, ecologist, and bioinformatician
>> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
>> > [hidden email]
>> > [hidden email]
>> >
>> >
>> >
>> > [image: Mailtrack]
>> > <
>>
>https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> > Sender
>> > notified by
>> > Mailtrack
>> > <
>>
>https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> > 04/09/19,
>> > 1:49:27 PM
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > [hidden email] 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]]
>
>______________________________________________
>[hidden email] 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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

Bert Gunter-2
In reply to this post by msnyder424
1. I am quite sure that whatever it is that you want to do can be done.
Probably straightforwardly. The various R graphics systems are mature and
extensive.

2. But I, for one, do not understand from your post what it is that you
want to do.  Nor does anyone else apparently.

Cheers,

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Apr 9, 2019 at 8:10 PM Matthew Snyder <[hidden email]> wrote:

> Thanks, Jim.
>
> I appreciate your contributed answer, but neither of those make the desired
> plot either. I'm actually kind of shocked this isn't an easier more
> straightforward thing. It seems like this would be something that a user
> would want to do frequently. I can actually do this for single plots in
> ggplot. Maybe I should contact the authors of lattice and see if this is
> something they can help me with or if they would like to add this as a
> feature in the future...
>
> Matt
>
>
>
> *Matthew R. Snyder*
> *~~~~~~~~~~~~~~~~~*
> PhD Candidate
> University Fellow
> University of Toledo
> Computational biologist, ecologist, and bioinformatician
> Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> [hidden email]
> [hidden email]
>
>
>
> [image: Mailtrack]
> <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> Sender
> notified by
> Mailtrack
> <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> 04/09/19,
> 7:52:27 PM
>
> On Tue, Apr 9, 2019 at 4:53 PM Jim Lemon <[hidden email]> wrote:
>
> > Hi Matthew,
> > How about this?
> >
> > library(lattice)
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        col = mtcars$gear,
> >        pch = mtcars$carb
> > )
> > library(plotrix)
> > grange<-range(mtcars$gear)
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        col =
> > color.scale(mtcars$gear,extremes=c("blue","red"),xrange=grange),
> >        pch = as.character(mtcars$carb)
> > )
> >
> > Jim
> >
> > On Wed, Apr 10, 2019 at 7:43 AM Matthew Snyder <[hidden email]>
> > wrote:
> > >
> > > I am making a lattice plot and I would like to use the value in one
> > column
> > > to define the pch and another column to define color of points.
> Something
> > > like:
> > >
> > > xyplot(mpg ~ wt | cyl,
> > >        data=mtcars,
> > >        col = gear,
> > >        pch = carb
> > > )
> > >
> > > There are unique pch points in the second and third panels, but these
> > > points are only unique within the plots, not among all the plots (as
> they
> > > should be). You can see this if you use the following code:
> > >
> > > xyplot(mpg ~ wt | cyl,
> > >        data=mtcars,
> > >        groups = carb
> > > )
> > >
> > > This plot looks great for one group, but if you try to invoke two
> groups
> > > using c(gear, carb) I think it simply takes unique combinations of
> those
> > > two variables and plots them as unique colors.
> > >
> > > Another solution given by a StackExchange user:
> > >
> > > mypch <- 1:6
> > > mycol <- 1:3
> > >
> > > xyplot(mpg ~ wt | cyl,
> > >           panel = function(x, y, ..., groups, subscripts) {
> > >               pch <- mypch[factor(carb[subscripts])]
> > >               col <- mycol[factor(gear[subscripts])]
> > >               grp <- c(gear,carb)
> > >               panel.xyplot(x, y, pch = pch, col = col)
> > >           }
> > > )
> > >
> > > This solution has the same problems as the code at the top. I think the
> > > issue causing problems with both solutions is that not every value for
> > each
> > > group is present in each panel, and they are almost never in the same
> > > order. I think R is just interpreting the appearance of unique values
> as
> > a
> > > signal to change to the next pch or color. My actual data file is very
> > > large, and it's not possible to sort my way out of this mess. It would
> be
> > > best if I could just use the value in two columns to actually define a
> > > color or pch for each point on an entire plot. Is there a way to do
> this?
> > >
> > > Ps, I had to post this via email because the Nabble site kept sending
> me
> > an
> > > error message: "Message rejected by filter rule match"
> > >
> > > Thanks,
> > > Matt
> > >
> > >
> > >
> > > *Matthew R. Snyder*
> > > *~~~~~~~~~~~~~~~~~*
> > > PhD Candidate
> > > University Fellow
> > > University of Toledo
> > > Computational biologist, ecologist, and bioinformatician
> > > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > > [hidden email]
> > > [hidden email]
> > >
> > >
> > >
> > > [image: Mailtrack]
> > > <
> >
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> > >
> > > Sender
> > > notified by
> > > Mailtrack
> > > <
> >
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> > >
> > > 04/09/19,
> > > 1:49:27 PM
> > >
> > >         [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] 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]]
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

msnyder424
I want to have one column in a dataframe define the color and another
define the pch.

This can be done easily with a single panel:

xyplot(mpg ~ wt,
       data=mtcars,
       col = mtcars$gear,
       pch = mtcars$carb
)

This produces the expected result: two pch that are the same color are
unique in the whole plot. But when you add cyl as a factor. Those two
points are only unique within their respective panels, and not across the
whole plot.

Matt



*Matthew R. Snyder*
*~~~~~~~~~~~~~~~~~*
PhD Candidate
University Fellow
University of Toledo
Computational biologist, ecologist, and bioinformatician
Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
[hidden email]
[hidden email]




[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
04/09/19,
9:26:09 PM

On Tue, Apr 9, 2019 at 9:23 PM Bert Gunter <[hidden email]> wrote:

> 1. I am quite sure that whatever it is that you want to do can be done.
> Probably straightforwardly. The various R graphics systems are mature and
> extensive.
>
> 2. But I, for one, do not understand from your post what it is that you
> want to do.  Nor does anyone else apparently.
>
> Cheers,
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Apr 9, 2019 at 8:10 PM Matthew Snyder <[hidden email]>
> wrote:
>
>> Thanks, Jim.
>>
>> I appreciate your contributed answer, but neither of those make the
>> desired
>> plot either. I'm actually kind of shocked this isn't an easier more
>> straightforward thing. It seems like this would be something that a user
>> would want to do frequently. I can actually do this for single plots in
>> ggplot. Maybe I should contact the authors of lattice and see if this is
>> something they can help me with or if they would like to add this as a
>> feature in the future...
>>
>> Matt
>>
>>
>>
>> *Matthew R. Snyder*
>> *~~~~~~~~~~~~~~~~~*
>> PhD Candidate
>> University Fellow
>> University of Toledo
>> Computational biologist, ecologist, and bioinformatician
>> Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
>> [hidden email]
>> [hidden email]
>>
>>
>>
>> [image: Mailtrack]
>> <
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> Sender
>> notified by
>> Mailtrack
>> <
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> 04/09/19,
>> 7:52:27 PM
>>
>> On Tue, Apr 9, 2019 at 4:53 PM Jim Lemon <[hidden email]> wrote:
>>
>> > Hi Matthew,
>> > How about this?
>> >
>> > library(lattice)
>> > xyplot(mpg ~ wt | cyl,
>> >        data=mtcars,
>> >        col = mtcars$gear,
>> >        pch = mtcars$carb
>> > )
>> > library(plotrix)
>> > grange<-range(mtcars$gear)
>> > xyplot(mpg ~ wt | cyl,
>> >        data=mtcars,
>> >        col =
>> > color.scale(mtcars$gear,extremes=c("blue","red"),xrange=grange),
>> >        pch = as.character(mtcars$carb)
>> > )
>> >
>> > Jim
>> >
>> > On Wed, Apr 10, 2019 at 7:43 AM Matthew Snyder <[hidden email]>
>> > wrote:
>> > >
>> > > I am making a lattice plot and I would like to use the value in one
>> > column
>> > > to define the pch and another column to define color of points.
>> Something
>> > > like:
>> > >
>> > > xyplot(mpg ~ wt | cyl,
>> > >        data=mtcars,
>> > >        col = gear,
>> > >        pch = carb
>> > > )
>> > >
>> > > There are unique pch points in the second and third panels, but these
>> > > points are only unique within the plots, not among all the plots (as
>> they
>> > > should be). You can see this if you use the following code:
>> > >
>> > > xyplot(mpg ~ wt | cyl,
>> > >        data=mtcars,
>> > >        groups = carb
>> > > )
>> > >
>> > > This plot looks great for one group, but if you try to invoke two
>> groups
>> > > using c(gear, carb) I think it simply takes unique combinations of
>> those
>> > > two variables and plots them as unique colors.
>> > >
>> > > Another solution given by a StackExchange user:
>> > >
>> > > mypch <- 1:6
>> > > mycol <- 1:3
>> > >
>> > > xyplot(mpg ~ wt | cyl,
>> > >           panel = function(x, y, ..., groups, subscripts) {
>> > >               pch <- mypch[factor(carb[subscripts])]
>> > >               col <- mycol[factor(gear[subscripts])]
>> > >               grp <- c(gear,carb)
>> > >               panel.xyplot(x, y, pch = pch, col = col)
>> > >           }
>> > > )
>> > >
>> > > This solution has the same problems as the code at the top. I think
>> the
>> > > issue causing problems with both solutions is that not every value for
>> > each
>> > > group is present in each panel, and they are almost never in the same
>> > > order. I think R is just interpreting the appearance of unique values
>> as
>> > a
>> > > signal to change to the next pch or color. My actual data file is very
>> > > large, and it's not possible to sort my way out of this mess. It
>> would be
>> > > best if I could just use the value in two columns to actually define a
>> > > color or pch for each point on an entire plot. Is there a way to do
>> this?
>> > >
>> > > Ps, I had to post this via email because the Nabble site kept sending
>> me
>> > an
>> > > error message: "Message rejected by filter rule match"
>> > >
>> > > Thanks,
>> > > Matt
>> > >
>> > >
>> > >
>> > > *Matthew R. Snyder*
>> > > *~~~~~~~~~~~~~~~~~*
>> > > PhD Candidate
>> > > University Fellow
>> > > University of Toledo
>> > > Computational biologist, ecologist, and bioinformatician
>> > > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
>> > > [hidden email]
>> > > [hidden email]
>> > >
>> > >
>> > >
>> > > [image: Mailtrack]
>> > > <
>> >
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> > >
>> > > Sender
>> > > notified by
>> > > Mailtrack
>> > > <
>> >
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> > >
>> > > 04/09/19,
>> > > 1:49:27 PM
>> > >
>> > >         [[alternative HTML version deleted]]
>> > >
>> > > ______________________________________________
>> > > [hidden email] 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]]
>>
>> ______________________________________________
>> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

msnyder424
In reply to this post by Jeff Newmiller
I tried this too:

xyplot(mpg ~ wt | cyl, data=mtcars,
       # groups = carb,
       subscripts = TRUE,
       col = as.factor(mtcars$gear),
       pch = as.factor(mtcars$carb)
)

Same problem...


*Matthew R. Snyder*
*~~~~~~~~~~~~~~~~~*
PhD Candidate
University Fellow
University of Toledo
Computational biologist, ecologist, and bioinformatician
Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
[hidden email]
[hidden email]




[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
04/09/19,
9:28:11 PM

On Tue, Apr 9, 2019 at 8:18 PM Jeff Newmiller <[hidden email]>
wrote:

> Maybe you should use factors rather than character columns.
>
> On April 9, 2019 8:09:43 PM PDT, Matthew Snyder <[hidden email]>
> wrote:
> >Thanks, Jim.
> >
> >I appreciate your contributed answer, but neither of those make the
> >desired
> >plot either. I'm actually kind of shocked this isn't an easier more
> >straightforward thing. It seems like this would be something that a
> >user
> >would want to do frequently. I can actually do this for single plots in
> >ggplot. Maybe I should contact the authors of lattice and see if this
> >is
> >something they can help me with or if they would like to add this as a
> >feature in the future...
> >
> >Matt
> >
> >
> >
> >*Matthew R. Snyder*
> >*~~~~~~~~~~~~~~~~~*
> >PhD Candidate
> >University Fellow
> >University of Toledo
> >Computational biologist, ecologist, and bioinformatician
> >Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> >[hidden email]
> >[hidden email]
> >
> >
> >
> >[image: Mailtrack]
> ><
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> >Sender
> >notified by
> >Mailtrack
> ><
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> >04/09/19,
> >7:52:27 PM
> >
> >On Tue, Apr 9, 2019 at 4:53 PM Jim Lemon <[hidden email]> wrote:
> >
> >> Hi Matthew,
> >> How about this?
> >>
> >> library(lattice)
> >> xyplot(mpg ~ wt | cyl,
> >>        data=mtcars,
> >>        col = mtcars$gear,
> >>        pch = mtcars$carb
> >> )
> >> library(plotrix)
> >> grange<-range(mtcars$gear)
> >> xyplot(mpg ~ wt | cyl,
> >>        data=mtcars,
> >>        col =
> >> color.scale(mtcars$gear,extremes=c("blue","red"),xrange=grange),
> >>        pch = as.character(mtcars$carb)
> >> )
> >>
> >> Jim
> >>
> >> On Wed, Apr 10, 2019 at 7:43 AM Matthew Snyder <[hidden email]>
> >> wrote:
> >> >
> >> > I am making a lattice plot and I would like to use the value in one
> >> column
> >> > to define the pch and another column to define color of points.
> >Something
> >> > like:
> >> >
> >> > xyplot(mpg ~ wt | cyl,
> >> >        data=mtcars,
> >> >        col = gear,
> >> >        pch = carb
> >> > )
> >> >
> >> > There are unique pch points in the second and third panels, but
> >these
> >> > points are only unique within the plots, not among all the plots
> >(as they
> >> > should be). You can see this if you use the following code:
> >> >
> >> > xyplot(mpg ~ wt | cyl,
> >> >        data=mtcars,
> >> >        groups = carb
> >> > )
> >> >
> >> > This plot looks great for one group, but if you try to invoke two
> >groups
> >> > using c(gear, carb) I think it simply takes unique combinations of
> >those
> >> > two variables and plots them as unique colors.
> >> >
> >> > Another solution given by a StackExchange user:
> >> >
> >> > mypch <- 1:6
> >> > mycol <- 1:3
> >> >
> >> > xyplot(mpg ~ wt | cyl,
> >> >           panel = function(x, y, ..., groups, subscripts) {
> >> >               pch <- mypch[factor(carb[subscripts])]
> >> >               col <- mycol[factor(gear[subscripts])]
> >> >               grp <- c(gear,carb)
> >> >               panel.xyplot(x, y, pch = pch, col = col)
> >> >           }
> >> > )
> >> >
> >> > This solution has the same problems as the code at the top. I think
> >the
> >> > issue causing problems with both solutions is that not every value
> >for
> >> each
> >> > group is present in each panel, and they are almost never in the
> >same
> >> > order. I think R is just interpreting the appearance of unique
> >values as
> >> a
> >> > signal to change to the next pch or color. My actual data file is
> >very
> >> > large, and it's not possible to sort my way out of this mess. It
> >would be
> >> > best if I could just use the value in two columns to actually
> >define a
> >> > color or pch for each point on an entire plot. Is there a way to do
> >this?
> >> >
> >> > Ps, I had to post this via email because the Nabble site kept
> >sending me
> >> an
> >> > error message: "Message rejected by filter rule match"
> >> >
> >> > Thanks,
> >> > Matt
> >> >
> >> >
> >> >
> >> > *Matthew R. Snyder*
> >> > *~~~~~~~~~~~~~~~~~*
> >> > PhD Candidate
> >> > University Fellow
> >> > University of Toledo
> >> > Computational biologist, ecologist, and bioinformatician
> >> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> >> > [hidden email]
> >> > [hidden email]
> >> >
> >> >
> >> >
> >> > [image: Mailtrack]
> >> > <
> >>
> >
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >> >
> >> > Sender
> >> > notified by
> >> > Mailtrack
> >> > <
> >>
> >
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >> >
> >> > 04/09/19,
> >> > 1:49:27 PM
> >> >
> >> >         [[alternative HTML version deleted]]
> >> >
> >> > ______________________________________________
> >> > [hidden email] 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]]
> >
> >______________________________________________
> >[hidden email] 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.
>
> --
> Sent from my phone. Please excuse my brevity.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

plangfelder
In reply to this post by msnyder424
Sorry for being late to the party, but has anyone suggested a minor
but important modification of the code from stack exchange?

xyplot(mpg ~ wt | cyl,
          panel = function(x, y, ..., groups, subscripts) {
              pch <- mypch[factor(carb)[subscripts]]
              col <- mycol[factor(gear)[subscripts]]
              grp <- c(gear,carb)
              panel.xyplot(x, y, pch = pch, col = col)
          }
)

From the little I understand about what you're trying to do, this may
just do the trick.

Peter

On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder <[hidden email]> wrote:

>
> I am making a lattice plot and I would like to use the value in one column
> to define the pch and another column to define color of points. Something
> like:
>
> xyplot(mpg ~ wt | cyl,
>        data=mtcars,
>        col = gear,
>        pch = carb
> )
>
> There are unique pch points in the second and third panels, but these
> points are only unique within the plots, not among all the plots (as they
> should be). You can see this if you use the following code:
>
> xyplot(mpg ~ wt | cyl,
>        data=mtcars,
>        groups = carb
> )
>
> This plot looks great for one group, but if you try to invoke two groups
> using c(gear, carb) I think it simply takes unique combinations of those
> two variables and plots them as unique colors.
>
> Another solution given by a StackExchange user:
>
> mypch <- 1:6
> mycol <- 1:3
>
> xyplot(mpg ~ wt | cyl,
>           panel = function(x, y, ..., groups, subscripts) {
>               pch <- mypch[factor(carb[subscripts])]
>               col <- mycol[factor(gear[subscripts])]
>               grp <- c(gear,carb)
>               panel.xyplot(x, y, pch = pch, col = col)
>           }
> )
>
> This solution has the same problems as the code at the top. I think the
> issue causing problems with both solutions is that not every value for each
> group is present in each panel, and they are almost never in the same
> order. I think R is just interpreting the appearance of unique values as a
> signal to change to the next pch or color. My actual data file is very
> large, and it's not possible to sort my way out of this mess. It would be
> best if I could just use the value in two columns to actually define a
> color or pch for each point on an entire plot. Is there a way to do this?
>
> Ps, I had to post this via email because the Nabble site kept sending me an
> error message: "Message rejected by filter rule match"
>
> Thanks,
> Matt
>
>
>
> *Matthew R. Snyder*
> *~~~~~~~~~~~~~~~~~*
> PhD Candidate
> University Fellow
> University of Toledo
> Computational biologist, ecologist, and bioinformatician
> Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> [hidden email]
> [hidden email]
>
>
>
> [image: Mailtrack]
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
> Sender
> notified by
> Mailtrack
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
> 04/09/19,
> 1:49:27 PM
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

msnyder424
You are not late to the party. And you solved it!

Thank you very much. You just made my PhD a little closer to reality!

Matt



*Matthew R. Snyder*
*~~~~~~~~~~~~~~~~~*
PhD Candidate
University Fellow
University of Toledo
Computational biologist, ecologist, and bioinformatician
Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
[hidden email]
[hidden email]



[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
04/09/19,
10:01:53 PM

On Tue, Apr 9, 2019 at 9:37 PM Peter Langfelder <[hidden email]>
wrote:

> Sorry for being late to the party, but has anyone suggested a minor
> but important modification of the code from stack exchange?
>
> xyplot(mpg ~ wt | cyl,
>           panel = function(x, y, ..., groups, subscripts) {
>               pch <- mypch[factor(carb)[subscripts]]
>               col <- mycol[factor(gear)[subscripts]]
>               grp <- c(gear,carb)
>               panel.xyplot(x, y, pch = pch, col = col)
>           }
> )
>
> From the little I understand about what you're trying to do, this may
> just do the trick.
>
> Peter
>
> On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder <[hidden email]>
> wrote:
> >
> > I am making a lattice plot and I would like to use the value in one
> column
> > to define the pch and another column to define color of points. Something
> > like:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        col = gear,
> >        pch = carb
> > )
> >
> > There are unique pch points in the second and third panels, but these
> > points are only unique within the plots, not among all the plots (as they
> > should be). You can see this if you use the following code:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        groups = carb
> > )
> >
> > This plot looks great for one group, but if you try to invoke two groups
> > using c(gear, carb) I think it simply takes unique combinations of those
> > two variables and plots them as unique colors.
> >
> > Another solution given by a StackExchange user:
> >
> > mypch <- 1:6
> > mycol <- 1:3
> >
> > xyplot(mpg ~ wt | cyl,
> >           panel = function(x, y, ..., groups, subscripts) {
> >               pch <- mypch[factor(carb[subscripts])]
> >               col <- mycol[factor(gear[subscripts])]
> >               grp <- c(gear,carb)
> >               panel.xyplot(x, y, pch = pch, col = col)
> >           }
> > )
> >
> > This solution has the same problems as the code at the top. I think the
> > issue causing problems with both solutions is that not every value for
> each
> > group is present in each panel, and they are almost never in the same
> > order. I think R is just interpreting the appearance of unique values as
> a
> > signal to change to the next pch or color. My actual data file is very
> > large, and it's not possible to sort my way out of this mess. It would be
> > best if I could just use the value in two columns to actually define a
> > color or pch for each point on an entire plot. Is there a way to do this?
> >
> > Ps, I had to post this via email because the Nabble site kept sending me
> an
> > error message: "Message rejected by filter rule match"
> >
> > Thanks,
> > Matt
> >
> >
> >
> > *Matthew R. Snyder*
> > *~~~~~~~~~~~~~~~~~*
> > PhD Candidate
> > University Fellow
> > University of Toledo
> > Computational biologist, ecologist, and bioinformatician
> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > [hidden email]
> > [hidden email]
> >
> >
> >
> > [image: Mailtrack]
> > <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> > Sender
> > notified by
> > Mailtrack
> > <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> > 04/09/19,
> > 1:49:27 PM
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

Richard M. Heiberger
In reply to this post by plangfelder
conditions look better as factors (their values are displayed in the
strip label).
groups should be a factor to get the uniqueness over panels.
To use two factors together for groups, take their interaction.
col and pch should be integers


xyplot(mpg ~ wt | factor(cyl), data=mtcars,
       groups = factor(carb),
       col = mtcars$gear,
       pch = mtcars$carb
)
xyplot(mpg ~ wt | factor(cyl), data=mtcars,
       groups = interaction(factor(carb), factor(gear)),
       col = mtcars$gear,
       pch = mtcars$carb
)

On Wed, Apr 10, 2019 at 12:54 AM Peter Langfelder
<[hidden email]> wrote:

>
> Sorry for being late to the party, but has anyone suggested a minor
> but important modification of the code from stack exchange?
>
> xyplot(mpg ~ wt | cyl,
>           panel = function(x, y, ..., groups, subscripts) {
>               pch <- mypch[factor(carb)[subscripts]]
>               col <- mycol[factor(gear)[subscripts]]
>               grp <- c(gear,carb)
>               panel.xyplot(x, y, pch = pch, col = col)
>           }
> )
>
> From the little I understand about what you're trying to do, this may
> just do the trick.
>
> Peter
>
> On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder <[hidden email]> wrote:
> >
> > I am making a lattice plot and I would like to use the value in one column
> > to define the pch and another column to define color of points. Something
> > like:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        col = gear,
> >        pch = carb
> > )
> >
> > There are unique pch points in the second and third panels, but these
> > points are only unique within the plots, not among all the plots (as they
> > should be). You can see this if you use the following code:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        groups = carb
> > )
> >
> > This plot looks great for one group, but if you try to invoke two groups
> > using c(gear, carb) I think it simply takes unique combinations of those
> > two variables and plots them as unique colors.
> >
> > Another solution given by a StackExchange user:
> >
> > mypch <- 1:6
> > mycol <- 1:3
> >
> > xyplot(mpg ~ wt | cyl,
> >           panel = function(x, y, ..., groups, subscripts) {
> >               pch <- mypch[factor(carb[subscripts])]
> >               col <- mycol[factor(gear[subscripts])]
> >               grp <- c(gear,carb)
> >               panel.xyplot(x, y, pch = pch, col = col)
> >           }
> > )
> >
> > This solution has the same problems as the code at the top. I think the
> > issue causing problems with both solutions is that not every value for each
> > group is present in each panel, and they are almost never in the same
> > order. I think R is just interpreting the appearance of unique values as a
> > signal to change to the next pch or color. My actual data file is very
> > large, and it's not possible to sort my way out of this mess. It would be
> > best if I could just use the value in two columns to actually define a
> > color or pch for each point on an entire plot. Is there a way to do this?
> >
> > Ps, I had to post this via email because the Nabble site kept sending me an
> > error message: "Message rejected by filter rule match"
> >
> > Thanks,
> > Matt
> >
> >
> >
> > *Matthew R. Snyder*
> > *~~~~~~~~~~~~~~~~~*
> > PhD Candidate
> > University Fellow
> > University of Toledo
> > Computational biologist, ecologist, and bioinformatician
> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > [hidden email]
> > [hidden email]
> >
> >
> >
> > [image: Mailtrack]
> > <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
> > Sender
> > notified by
> > Mailtrack
> > <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
> > 04/09/19,
> > 1:49:27 PM
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

plangfelder
In reply to this post by msnyder424
Glad to be of help.

Peter

On Tue, Apr 9, 2019 at 10:03 PM Matthew Snyder <[hidden email]> wrote:

> You are not late to the party. And you solved it!
>
> Thank you very much. You just made my PhD a little closer to reality!
>
> Matt
>
>
>
> *Matthew R. Snyder*
> *~~~~~~~~~~~~~~~~~*
> PhD Candidate
> University Fellow
> University of Toledo
> Computational biologist, ecologist, and bioinformatician
> Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> [hidden email]
> [hidden email]
>
>
>
> [image: Mailtrack]
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&> Sender
> notified by
> Mailtrack
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&> 04/09/19,
> 10:01:53 PM
>
> On Tue, Apr 9, 2019 at 9:37 PM Peter Langfelder <
> [hidden email]> wrote:
>
>> Sorry for being late to the party, but has anyone suggested a minor
>> but important modification of the code from stack exchange?
>>
>> xyplot(mpg ~ wt | cyl,
>>           panel = function(x, y, ..., groups, subscripts) {
>>               pch <- mypch[factor(carb)[subscripts]]
>>               col <- mycol[factor(gear)[subscripts]]
>>               grp <- c(gear,carb)
>>               panel.xyplot(x, y, pch = pch, col = col)
>>           }
>> )
>>
>> From the little I understand about what you're trying to do, this may
>> just do the trick.
>>
>> Peter
>>
>> On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder <[hidden email]>
>> wrote:
>> >
>> > I am making a lattice plot and I would like to use the value in one
>> column
>> > to define the pch and another column to define color of points.
>> Something
>> > like:
>> >
>> > xyplot(mpg ~ wt | cyl,
>> >        data=mtcars,
>> >        col = gear,
>> >        pch = carb
>> > )
>> >
>> > There are unique pch points in the second and third panels, but these
>> > points are only unique within the plots, not among all the plots (as
>> they
>> > should be). You can see this if you use the following code:
>> >
>> > xyplot(mpg ~ wt | cyl,
>> >        data=mtcars,
>> >        groups = carb
>> > )
>> >
>> > This plot looks great for one group, but if you try to invoke two groups
>> > using c(gear, carb) I think it simply takes unique combinations of those
>> > two variables and plots them as unique colors.
>> >
>> > Another solution given by a StackExchange user:
>> >
>> > mypch <- 1:6
>> > mycol <- 1:3
>> >
>> > xyplot(mpg ~ wt | cyl,
>> >           panel = function(x, y, ..., groups, subscripts) {
>> >               pch <- mypch[factor(carb[subscripts])]
>> >               col <- mycol[factor(gear[subscripts])]
>> >               grp <- c(gear,carb)
>> >               panel.xyplot(x, y, pch = pch, col = col)
>> >           }
>> > )
>> >
>> > This solution has the same problems as the code at the top. I think the
>> > issue causing problems with both solutions is that not every value for
>> each
>> > group is present in each panel, and they are almost never in the same
>> > order. I think R is just interpreting the appearance of unique values
>> as a
>> > signal to change to the next pch or color. My actual data file is very
>> > large, and it's not possible to sort my way out of this mess. It would
>> be
>> > best if I could just use the value in two columns to actually define a
>> > color or pch for each point on an entire plot. Is there a way to do
>> this?
>> >
>> > Ps, I had to post this via email because the Nabble site kept sending
>> me an
>> > error message: "Message rejected by filter rule match"
>> >
>> > Thanks,
>> > Matt
>> >
>> >
>> >
>> > *Matthew R. Snyder*
>> > *~~~~~~~~~~~~~~~~~*
>> > PhD Candidate
>> > University Fellow
>> > University of Toledo
>> > Computational biologist, ecologist, and bioinformatician
>> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
>> > [hidden email]
>> > [hidden email]
>> >
>> >
>> >
>> > [image: Mailtrack]
>> > <
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> > Sender
>> > notified by
>> > Mailtrack
>> > <
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> > 04/09/19,
>> > 1:49:27 PM
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

Bert Gunter-2
In reply to this post by plangfelder
I believe this is unnecessarily complicated. What the OP did not seem to
get is that he had to specify the col's and pch's in the panel function
that were actually used via appropriate subscripting. He just passed in the
whole col and pch vector by default -- subscripting is not done unless
specified.So the following does what I think he wants very simply:

xyplot(mpg ~wt|cyl, data = mtcars,
      col = mtcars$gear,
      pch = mtcars$carb,
      panel = function(x,y, subscripts, col, pch,...)
      {
         panel.xyplot(x,y, col = col[subscripts], pch = pch[subscripts] )
      })

Cheers,
Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Apr 9, 2019 at 9:53 PM Peter Langfelder <[hidden email]>
wrote:

> Sorry for being late to the party, but has anyone suggested a minor
> but important modification of the code from stack exchange?
>
> xyplot(mpg ~ wt | cyl,
>           panel = function(x, y, ..., groups, subscripts) {
>               pch <- mypch[factor(carb)[subscripts]]
>               col <- mycol[factor(gear)[subscripts]]
>               grp <- c(gear,carb)
>               panel.xyplot(x, y, pch = pch, col = col)
>           }
> )
>
> From the little I understand about what you're trying to do, this may
> just do the trick.
>
> Peter
>
> On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder <[hidden email]>
> wrote:
> >
> > I am making a lattice plot and I would like to use the value in one
> column
> > to define the pch and another column to define color of points. Something
> > like:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        col = gear,
> >        pch = carb
> > )
> >
> > There are unique pch points in the second and third panels, but these
> > points are only unique within the plots, not among all the plots (as they
> > should be). You can see this if you use the following code:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        groups = carb
> > )
> >
> > This plot looks great for one group, but if you try to invoke two groups
> > using c(gear, carb) I think it simply takes unique combinations of those
> > two variables and plots them as unique colors.
> >
> > Another solution given by a StackExchange user:
> >
> > mypch <- 1:6
> > mycol <- 1:3
> >
> > xyplot(mpg ~ wt | cyl,
> >           panel = function(x, y, ..., groups, subscripts) {
> >               pch <- mypch[factor(carb[subscripts])]
> >               col <- mycol[factor(gear[subscripts])]
> >               grp <- c(gear,carb)
> >               panel.xyplot(x, y, pch = pch, col = col)
> >           }
> > )
> >
> > This solution has the same problems as the code at the top. I think the
> > issue causing problems with both solutions is that not every value for
> each
> > group is present in each panel, and they are almost never in the same
> > order. I think R is just interpreting the appearance of unique values as
> a
> > signal to change to the next pch or color. My actual data file is very
> > large, and it's not possible to sort my way out of this mess. It would be
> > best if I could just use the value in two columns to actually define a
> > color or pch for each point on an entire plot. Is there a way to do this?
> >
> > Ps, I had to post this via email because the Nabble site kept sending me
> an
> > error message: "Message rejected by filter rule match"
> >
> > Thanks,
> > Matt
> >
> >
> >
> > *Matthew R. Snyder*
> > *~~~~~~~~~~~~~~~~~*
> > PhD Candidate
> > University Fellow
> > University of Toledo
> > Computational biologist, ecologist, and bioinformatician
> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > [hidden email]
> > [hidden email]
> >
> >
> >
> > [image: Mailtrack]
> > <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> > Sender
> > notified by
> > Mailtrack
> > <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
> >
> > 04/09/19,
> > 1:49:27 PM
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Define pch and color based on two different columns

Duncan Mackay-4
In reply to this post by msnyder424
Hi

Here is the caveat
If you want to repeat it with loess? or panel loess something else that is
not groups aware  (I have not checked to see if it has been up dated) have a
look at

https://stat.ethz.ch/pipermail/r-help/2010-August/250050.html

Regards

Duncan Mackay

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350


-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Matthew
Snyder
Sent: Wednesday, 10 April 2019 15:03
To: Peter Langfelder
Cc: r-help
Subject: Re: [R] Define pch and color based on two different columns

You are not late to the party. And you solved it!

Thank you very much. You just made my PhD a little closer to reality!

Matt



*Matthew R. Snyder*
*~~~~~~~~~~~~~~~~~*
PhD Candidate
University Fellow
University of Toledo
Computational biologist, ecologist, and bioinformatician
Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
[hidden email]
[hidden email]



[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=sig
naturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=sig
naturevirality5&>
04/09/19,
10:01:53 PM

On Tue, Apr 9, 2019 at 9:37 PM Peter Langfelder <[hidden email]>
wrote:

> Sorry for being late to the party, but has anyone suggested a minor
> but important modification of the code from stack exchange?
>
> xyplot(mpg ~ wt | cyl,
>           panel = function(x, y, ..., groups, subscripts) {
>               pch <- mypch[factor(carb)[subscripts]]
>               col <- mycol[factor(gear)[subscripts]]
>               grp <- c(gear,carb)
>               panel.xyplot(x, y, pch = pch, col = col)
>           }
> )
>
> From the little I understand about what you're trying to do, this may
> just do the trick.
>
> Peter
>
> On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder <[hidden email]>
> wrote:
> >
> > I am making a lattice plot and I would like to use the value in one
> column
> > to define the pch and another column to define color of points.
Something

> > like:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        col = gear,
> >        pch = carb
> > )
> >
> > There are unique pch points in the second and third panels, but these
> > points are only unique within the plots, not among all the plots (as
they

> > should be). You can see this if you use the following code:
> >
> > xyplot(mpg ~ wt | cyl,
> >        data=mtcars,
> >        groups = carb
> > )
> >
> > This plot looks great for one group, but if you try to invoke two groups
> > using c(gear, carb) I think it simply takes unique combinations of those
> > two variables and plots them as unique colors.
> >
> > Another solution given by a StackExchange user:
> >
> > mypch <- 1:6
> > mycol <- 1:3
> >
> > xyplot(mpg ~ wt | cyl,
> >           panel = function(x, y, ..., groups, subscripts) {
> >               pch <- mypch[factor(carb[subscripts])]
> >               col <- mycol[factor(gear[subscripts])]
> >               grp <- c(gear,carb)
> >               panel.xyplot(x, y, pch = pch, col = col)
> >           }
> > )
> >
> > This solution has the same problems as the code at the top. I think the
> > issue causing problems with both solutions is that not every value for
> each
> > group is present in each panel, and they are almost never in the same
> > order. I think R is just interpreting the appearance of unique values as
> a
> > signal to change to the next pch or color. My actual data file is very
> > large, and it's not possible to sort my way out of this mess. It would
be
> > best if I could just use the value in two columns to actually define a
> > color or pch for each point on an entire plot. Is there a way to do
this?

> >
> > Ps, I had to post this via email because the Nabble site kept sending me
> an
> > error message: "Message rejected by filter rule match"
> >
> > Thanks,
> > Matt
> >
> >
> >
> > *Matthew R. Snyder*
> > *~~~~~~~~~~~~~~~~~*
> > PhD Candidate
> > University Fellow
> > University of Toledo
> > Computational biologist, ecologist, and bioinformatician
> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > [hidden email]
> > [hidden email]
> >
> >
> >
> > [image: Mailtrack]
> > <
>
https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=sign
aturevirality5&
> >
> > Sender
> > notified by
> > Mailtrack
> > <
>
https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=sign
aturevirality5&

> >
> > 04/09/19,
> > 1:49:27 PM
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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]]

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.