Re: [R] Lattice wireframe or cloud plot with different colours by a group

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Sat, 02 Apr 2011 07:14:28 -0400

On Apr 1, 2011, at 7:46 PM, David Winsemius wrote:

>
> On Apr 1, 2011, at 6:21 PM, Pam Allen wrote:
>
>> I have a question about wireframe 3-D plots and how to apply
>> colors. I have
>> a large dataset of river flow (m^3/s) over time, and I have coded
>> these
>> flows based on their height. I would like to produce a wireframe
>> plot that
>> colors the graph based on the flow code, i.e. I would like high
>> flows to be
>> red, medium to be green and low flows to be blue. Here is some
>> sample data
>> with the basic wireframe plot:
>>
>> flow.dat=cbind.data.frame(flow=sin(2*pi/53*c(1:3000))
>> +1,day=as.numeric(format(as.Date(c(1:3000)),
>> format="%j")), year=as.numeric(format(as.Date(c(1:3000)),
>> format="%Y")),grp=c(rep(c("1.high","2.med","3.low"),1000)))
>
> It does not look to me that high flows are properly grouped with
> `grp`.
>
>>
>> wireframe(flow~day*year, data=flow.dat, shade=T)
>
> wireframe(flow~day*year, data=flow.dat, drape=TRUE,
> col.regions=c("#FF3030","#551A8B","#43CD80"),
> at=c(0,.6,1.3,1.8))
>
> Because of the coding at the corner and the long thin polygons you
> have specified with your day*year splits you get slanting colors.

If you want to use grp as the color index then you need first to convert it to something that can be used as an index (with as.numeric), then use that in "[" to pull from a vector of colors:

cloud(flow~day*year,

       data=flow.dat,
       col=c("#FF3030", "#551A8B", "#43CD80")[
                        as.numeric(flow.dat$grp)],
       pch=20)

-- 
David

>
>>
>> Is there any way to specify what colours are passed to the plot?
>> I.e.
>> wireframe(flow~day*year, data=flow.dat, shade=T, groups=grp,
>> col.group=c("#FF3030","#551A8B","#43CD80"))
>>
>> I would also be happy if I could do this with a cloud plot, but I
>> can't get
>> the colors to plot correctly.
>> cloud(flow~day*year, data=flow.dat, shade=T, groups=grp,
>> col.group=c("#FF3030","#43CD80","#1E90FF"), pch=20)
>>
>> Any help is much appreciated! Thank you.
>>
>> -Pam Allen
>>
>> allen_pam_at_hotmail.com
>>
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/Lattice-wireframe-or-cloud-plot-with-different-colours-by-a-group-tp3421296p3421296.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> 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.
David Winsemius, MD West Hartford, CT ______________________________________________ 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.
Received on Sat 02 Apr 2011 - 12:42:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 02 Apr 2011 - 15:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive