[R] Lattice barchart with different fill pattern
Dear list, I am new to lattice plots. I want to make a barchart with 10 and more levels. I need to use a grey scale for printing purposes. The problem is that with 10 or more levels in factors it is very difficult to distinguish each level in the plot and legend, since the greys are very similar (some levels have value of zero and don't appear). Here is an example of my problem: df - data.frame(year = rep(1996:2005,10), spe = c(rep(aa,10), rep(bb,10), rep(cc,10), rep(dd,10), rep(ee,10), rep(ff,10), rep(gg,10), rep(hh,10),rep(ii,10),rep(jj,10)), value = sample( c(0:10),100 , replace=TRUE) ) require(lattice) barchart( value ~ factor(year), groups = spe, data=df, stack = TRUE, main=, xlab=, auto.key = list(points = FALSE, rectangles = TRUE, space = right ), par.settings = list(superpose.polygon = list(col = gray.colors(10) ), scales = list(cex=0.8, rot=c(90,0,0))) ) I was thinking that by changing the fill pattern, the different levels could be better distinguished. I have read the lattice help and searched in the mailing list archives, but did no find any solution for lattice barchart. Is there a way to change the fill pattern of the bar levels or any other approach to help in the identification of the different levels in the barchart? Many thanks. Rafael Duarte OS: windows XP __ R-help@stat.math.ethz.ch 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.
[R] Lattice strip labels for two factors
Dear list, My problem is to change the strip text of lattice panels when using two factors. I have a data frame with two factors: df - expand.grid( fact1=c(y,b,r), fact2=c(far,por,lis,set), year=1991:2000, value= NA) df[,value] - sample(1:50, 120, replace=TRUE) I can make simple xyplot and change the text of the factor levels with strip.custom: require(lattice) xyplot( value ~ year | fact1, data=df, type=b, subset= fact2==far, strip = strip.custom(bg=gray.colors(1,0.95), factor.levels=c(yellow, black, red)), layout=c(1,3) ) But how can I change the text of the factor levels when using both factors as in this plot: xyplot( value ~ year | fact1*fact2, data=df, type=b) (fact2 levels text should change to: c(faro,porto,lisbon,setubal)) I read the help for strip.default and the emails archive, tried with which.given but could not find out how to accomplish this. Many thanks, Rafael Duarte -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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.
Re: [R] Lattice strip labels for two factors
Thank you for your suggestion. This could be a solution that I didn't think of. But I forgot to say that I didn't want to change the original data frame (I have other code that depends on the original df and on the original factor levels). I was looking more for an implementation directly in the xyplot call (same as I did for one factor). Is it possible/simple to do? Thank you, Rafael Gabor Grothendieck wrote: Try this: levels(df$fact2) - c(faro,porto,lisbon,setubal) xyplot( value ~ year | fact1*fact2, data=df, type=b) On 9/22/06, Rafael Duarte [EMAIL PROTECTED] wrote: Dear list, My problem is to change the strip text of lattice panels when using two factors. I have a data frame with two factors: df - expand.grid( fact1=c(y,b,r), fact2=c(far,por,lis,set), year=1991:2000, value= NA) df[,value] - sample(1:50, 120, replace=TRUE) I can make simple xyplot and change the text of the factor levels with strip.custom: require(lattice) xyplot( value ~ year | fact1, data=df, type=b, subset= fact2==far, strip = strip.custom(bg=gray.colors(1,0.95), factor.levels=c(yellow, black, red)), layout=c(1,3) ) But how can I change the text of the factor levels when using both factors as in this plot: xyplot( value ~ year | fact1*fact2, data=df, type=b) (fact2 levels text should change to: c(faro,porto,lisbon,setubal)) I read the help for strip.default and the emails archive, tried with which.given but could not find out how to accomplish this. Many thanks, Rafael Duarte -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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. -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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.
Re: [R] Lattice strip labels for two factors
Dear Gabor and Deepayan, Many thanks for your help. I used suggestion 3 from Gabor (it worked well with my long df ) and will try Deepayan's suggestion. Rafael Deepayan Sarkar wrote: On 9/23/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: 1. You can write a custom strip function: my.strip - function(which.given, ..., factor.levels) { levs - if (which.given == 1) factor.levels else c(faro, porto, lisbon, setubal) strip.default(which.given, ..., factor.levels = levs) } xyplot(value ~ year | fact1 * fact2, data = df, strip = my.strip) 2. however, its probably easier just to change the levels in the data frame. Just do it in a copy if you don't want to change the original one: df2 - df levels(df2$fact2) - c(faro, porto, lisbon, setubal) xyplot(value ~ year | fact1 * fact2, data = df2) 3. or you can even do it inline in the data statement which similarly won't change the original data frame: levs - c(faro, porto, lisbon, setubal) xyplot(value ~ year | fact1 * fact2, data = replace(df, fact2, structure(df$fact2, levels = levs))) head(df) # unchanged or even (untested) xyplot(value ~ year | fact1 * factor(fact2, levels = levels(fact2), labels = levs), data = df) Deepayan On 9/23/06, Rafael Duarte [EMAIL PROTECTED] wrote: Thank you for your suggestion. This could be a solution that I didn't think of. But I forgot to say that I didn't want to change the original data frame (I have other code that depends on the original df and on the original factor levels). I was looking more for an implementation directly in the xyplot call (same as I did for one factor). Is it possible/simple to do? Thank you, Rafael Gabor Grothendieck wrote: Try this: levels(df$fact2) - c(faro,porto,lisbon,setubal) xyplot( value ~ year | fact1*fact2, data=df, type=b) On 9/22/06, Rafael Duarte [EMAIL PROTECTED] wrote: Dear list, My problem is to change the strip text of lattice panels when using two factors. I have a data frame with two factors: df - expand.grid( fact1=c(y,b,r), fact2=c(far,por,lis,set), year=1991:2000, value= NA) df[,value] - sample(1:50, 120, replace=TRUE) I can make simple xyplot and change the text of the factor levels with strip.custom: require(lattice) xyplot( value ~ year | fact1, data=df, type=b, subset= fact2==far, strip = strip.custom(bg=gray.colors(1,0.95), factor.levels=c(yellow, black, red)), layout=c(1,3) ) But how can I change the text of the factor levels when using both factors as in this plot: xyplot( value ~ year | fact1*fact2, data=df, type=b) (fact2 levels text should change to: c(faro,porto,lisbon,setubal)) I read the help for strip.default and the emails archive, tried with which.given but could not find out how to accomplish this. Many thanks, Rafael Duarte -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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. -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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. __ R-help@stat.math.ethz.ch 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.
Re: [R] hierarhical cluster analysis of groups of vectors
It seems that you have already groups defined. Discriminant analysis would probably be more appropriate for what you want. Best regards, Rafael Duarte Anders Malmendal wrote: I want to do hierarchical cluster analysis to compare 10 groups of vectors with five vectors in each group (i.e. I want to make a dendogram showing the clustering of the different groups). I've looked into using dist and hclust, but cannot see how to compare the different groups instead of the individual vectors. I am thankful for any help. Anders __ R-help@stat.math.ethz.ch 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. -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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.
Re: [R] Fw: hierarhical cluster analysis of groups of vectors
Yes, of course. But since the initial question referred the use of dist(), (I suppose with Euclidean distances) and hclust on a matrix with a priori known groups, discriminant analysis seemed adequate to me. It was only a suggestion, without having much detail about the problem. Thanks, Rafael Ron Michael wrote: -- Hi Rafael, What about multivariate logistic regression? - Forwarded Message From: Rafael Duarte [EMAIL PROTECTED] To: Anders Malmendal [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Tuesday, May 29, 2007 3:21:11 PM Subject: Re: [R] hierarhical cluster analysis of groups of vectors It seems that you have already groups defined. Discriminant analysis would probably be more appropriate for what you want. Best regards, Rafael Duarte Anders Malmendal wrote: I want to do hierarchical cluster analysis to compare 10 groups of vectors with five vectors in each group (i.e. I want to make a dendogram showing the clustering of the different groups). I've looked into using dist and hclust, but cannot see how to compare the different groups instead of the individual vectors. I am thankful for any help. Anders __ R-help@stat.math.ethz.ch 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. -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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. Send instant messages to your online friends http://uk.messenger.yahoo.com -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Brasília, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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.