Re: R-help Digest, Vol 35, Issue 7

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

Re: R-help Digest, Vol 35, Issue 7

Evgeniy Kachalin
Hello, dear participants!

Could you tip me, is there any simple and nice way to build scatter-plot
for three different types of data (, and o and * - signs, for example)
with legend.

Now i can guess only that way:

plot(x~y,data=subset(mydata,factor1=='1'), pch='.',col='blue')
points(x~y,data=subset(mydata,factor1=='2'), pch='*',col='green')
points(.... etc

What is the simple and nice way?
Thank you very much for your kindness and help.

--
Evgeniy Kachalin

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: R-help Digest, Vol 35, Issue 7

Uwe Ligges
Evgeniy Kachalin wrote:

> Hello, dear participants!
>
> Could you tip me, is there any simple and nice way to build scatter-plot
> for three different types of data (, and o and * - signs, for example)
> with legend.
>
> Now i can guess only that way:
>
> plot(x~y,data=subset(mydata,factor1=='1'), pch='.',col='blue')
> points(x~y,data=subset(mydata,factor1=='2'), pch='*',col='green')
> points(.... etc
>
> What is the simple and nice way?
> Thank you very much for your kindness and help.
>


Example:


with(iris,
   plot(Sepal.Length, Sepal.Width, pch = as.integer(Species)))
with(iris,
   legend(7, 4.4, legend = unique(as.character(Species)),
                     pch = unique(as.integer(Species))))


Uwe Ligges

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: R-help Digest, Vol 35, Issue 7

Evgeniy Kachalin
Uwe Ligges пишет:

> Evgeniy Kachalin wrote:
>
>> Hello, dear participants!
>>
>> Could you tip me, is there any simple and nice way to build
>> scatter-plot for three different types of data (, and o and * - signs,
>> for example) with legend.
>>
>> Now i can guess only that way:
>>
>> plot(x~y,data=subset(mydata,factor1=='1'), pch='.',col='blue')
>> points(x~y,data=subset(mydata,factor1=='2'), pch='*',col='green')
>> points(.... etc
>>
>> What is the simple and nice way?
>> Thank you very much for your kindness and help.
>>
>
>
> Example:
>
>
> with(iris,
>   plot(Sepal.Length, Sepal.Width, pch = as.integer(Species)))
> with(iris,
>   legend(7, 4.4, legend = unique(as.character(Species)),
>                     pch = unique(as.integer(Species))))
>

Uwe, sorry for my stupid question. You mean that when pch=factor , plot
can recycle the factor and use it for subscripts or marks.

Then pch=as.integer(Species) results in c(1,2,3) for 3 factor levels.
And I need symbols 15,16,17 and colors red, blue, green.

So then I do:
iris$Species->spec.symb
iris$Species->spec.col
levels(spec.symb)<-c(15,16,17)
levels(spec.col)<-c('red','green','blue')

That's the only way?
More of that!!! 'Plot' does not like factors in 'pch'. So it must be so:
plot(x~y,data, pch=as.integer(as.character(spec.symb))).
That's totally crazy...

--
Evgeniy

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: R-help Digest, Vol 35, Issue 7

Kyosti H Kurikka
Hi!

Just use your factors for indexing c(15,16,17) and
c("red","green","blue"). So, with the iris data:

>with(iris, plot(Sepal.Length, Sepal.Width,
       pch=c(15,16,17)[as.integer(Species)],
       col=c("red","green","blue")[as.integer(Species)] ))

Best regards,
Kyosti Kurikka


> > Evgeniy Kachalin wrote:
> >
> >> Hello, dear participants!
> >>
> >> Could you tip me, is there any simple and nice way to build
> >> scatter-plot for three different types of data (, and o and * - signs,
> >> for example) with legend.
> >>
> >> Now i can guess only that way:
> >>
> >> plot(x~y,data=subset(mydata,factor1=='1'), pch='.',col='blue')
> >> points(x~y,data=subset(mydata,factor1=='2'), pch='*',col='green')
> >> points(.... etc
> >>
> >> What is the simple and nice way?
> >> Thank you very much for your kindness and help.
> >>
> >
> >
> > Example:
> >
> >
> > with(iris,
> >   plot(Sepal.Length, Sepal.Width, pch = as.integer(Species)))
> > with(iris,
> >   legend(7, 4.4, legend = unique(as.character(Species)),
> >                     pch = unique(as.integer(Species))))
> >
>
> Uwe, sorry for my stupid question. You mean that when pch=factor , plot
> can recycle the factor and use it for subscripts or marks.
>
> Then pch=as.integer(Species) results in c(1,2,3) for 3 factor levels.
> And I need symbols 15,16,17 and colors red, blue, green.
>
> So then I do:
> iris$Species->spec.symb
> iris$Species->spec.col
> levels(spec.symb)<-c(15,16,17)
> levels(spec.col)<-c('red','green','blue')
>
> That's the only way?
> More of that!!! 'Plot' does not like factors in 'pch'. So it must be so:
> plot(x~y,data, pch=as.integer(as.character(spec.symb))).
> That's totally crazy...
>
> --
> Evgeniy
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: R-help Digest, Vol 35, Issue 7

Uwe Ligges
In reply to this post by Evgeniy Kachalin
Evgeniy Kachalin wrote:

> Uwe Ligges пишет:
>
>> Evgeniy Kachalin wrote:
>>
>>> Hello, dear participants!
>>>
>>> Could you tip me, is there any simple and nice way to build
>>> scatter-plot for three different types of data (, and o and * -
>>> signs, for example) with legend.
>>>
>>> Now i can guess only that way:
>>>
>>> plot(x~y,data=subset(mydata,factor1=='1'), pch='.',col='blue')
>>> points(x~y,data=subset(mydata,factor1=='2'), pch='*',col='green')
>>> points(.... etc
>>>
>>> What is the simple and nice way?
>>> Thank you very much for your kindness and help.
>>>
>>
>>
>> Example:
>>
>>
>> with(iris,
>>   plot(Sepal.Length, Sepal.Width, pch = as.integer(Species)))
>> with(iris,
>>   legend(7, 4.4, legend = unique(as.character(Species)),
>>                     pch = unique(as.integer(Species))))
>>
>
> Uwe, sorry for my stupid question. You mean that when pch=factor , plot
> can recycle the factor and use it for subscripts or marks.

Yes, it can recycle, but in the example above it does not recycle but
takes the whole "Species" vector.


> Then pch=as.integer(Species) results in c(1,2,3) for 3 factor levels.
> And I need symbols 15,16,17 and colors red, blue, green.

What about adding 14 as in as.integer(Species)+14, or 1 for the colors,
respectively?



> So then I do:
> iris$Species->spec.symb
> iris$Species->spec.col
> levels(spec.symb)<-c(15,16,17)
> levels(spec.col)<-c('red','green','blue')
>
> That's the only way?

This is one qay of many.


> More of that!!! 'Plot' does not like factors in 'pch'. So it must be so:
> plot(x~y,data, pch=as.integer(as.character(spec.symb))).
> That's totally crazy...

You can set up your own pch variable of course, if you don't like it
this fast and easy way.

Uwe Ligges

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html