Re: [R] Help in installing and loading the BradleyTerry add on package in R
Kalyan Roy (DEL/MSG) wrote: > How do I install and load the BradleyTerry add on package in R 2.5.1 in > MSWindowsXP environment? > Hi Kalyan, If R CMD INSTALL doesn't work, you can use WinZip or Zip Reader to unzip the package to: C:\Program Files\R-2.5.1\library or whatever your path to the "library" directory is, and then hand edit the "packages.html" file in: C:\Program Files\R-2.5.1\doc\html to include the new package in your HTML listing. This will allow you to access the help files and use the package. Jim __ 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] command to plot variannce of data (like error bar plot)
Yogesh Tiwari wrote: > Hi, > > How to plot a variance over a data point, something like error bar. > Hi Yogesh, The generic method is to use the "arrows" function, and there are quite a few variations on this theme (in alpha order): brkdn.plot(plotrix) dispbars(plotrix) errbar(Hmisc and sfsmisc) plotCI(gplots and plotrix) plotMeans (Rcmdr) and there are surely more error bar functions of which I am unaware. Jim __ 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] Help with color coded bar graph
Luis Naver wrote: > I have a list of observations that are -1, 1 or 0. I would like to > represent them in a horizontal bar color coded based on value like a > stacked bar graph. I can achieve this in the form of a png with the > following code: > > A = floor(runif(10)*3) - 1 > > png(width=100, height=10) > par(mar=c(0,0,0,0)) > image(matrix(A), col=grey(c(0.1, 0.5, 0.9))) > dev.off() > > However I would like to do this with one of the standard plotting > tools (i.e. barplot) to take advantage of labels and multiple > series. Any help would be appreciated. > Hi Luis, I understood your request as wanting a single horizontal bar with 10 segments, each colored according to the value of A. If this is correct, you might want: library(plotrix) plot(1,xlim=c(-1,1),ylim=c(-1,1),xlab="",ylab="",type="n",axes=FALSE) gradient.rect(-1,-0.1,1,0.1,col=grey(c(0.1,0.5,0.9))[A+2]) Jim __ 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] list element to matrix
[EMAIL PROTECTED] wrote: > I have created a list of "matrices" using sapply or lapply and wish to > extract each of the "matrices" as a matrix. Some of them are 2x2, 3x3, etc. > > I can do this one at a time as: > > M1<-as.matrix(D[[1]]) > > How can repeat this process for an unknown number of entries in the list? In > other words, how shall I index M1? > Hi Diana, To step through the matrices in your list (assuming that it only has one level): for(mat in 1:length(D)) { } Jim __ 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] Pie Chart Labels
Adam Green wrote: > I am having trouble finding out how to adjust the position of labels on > pie charts. For the small wedges, many of the labels overlap making it > impossible to read. Is there any way to offset the labels so that they > don't overlap? > Hi Adam, There are three ways to adjust the positions of labels on a 3D pie chart (I'm assuming it's 3D from the word "wedges". If not, the following should still be useful). The first is to change the position of the sectors by the "start" argument. Apart from being useful when very large sectors cause problems, changing the sector positions can sometimes alleviate minor crowding of the labels. The second is to catch the return value of the pie3D function. This is the radial positions at which the labels have been placed. You can then alter this vector and pass it as the argument "labelpos". In this way you can spread out the labels for small sectors. Finally, you can leave out the labels when you call pie3D and manually place labels using the "text" function. The chart is drawn on a plot that spans -1 to 1 in both directions, so it is relatively easy to work out where the labels should be. A word of warning - when I read, "For the small wedges, many of the labels...", I felt that I should say that pie charts in general, and 3D ones in particular, are rarely successful with more than 4 or 5 sectors. In the R-news article that included pie3D, I included a pie chart that was very difficult for the viewer to extract the information that the creator intended. Depending upon what is to be represented, you might consider whether another method might be more successful. Jim __ 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] Incomplete rank functions
Hi folks, Thanks to my esteemed colleagues, I have been grappling with the analysis of incomplete ranks. These result from questions like: Number the three most important things from the following list in order from 1 to 3. OR Where some or all respondents or observers have not assigned ranks to some items. In doing so, I have programmed a few functions to impute values where all ranks have not been allocated. These are all based upon substituting the mean of all unallocated ranks for missing values for each set (row) of ranks. Ties can be handled and optionally expanded to cover the values that would have resulted if the ties had not occurred. This satisfies the assumption that all sets of ranks sum to the same value, and infers that the unranked items were not distinguished by the ranker. I searched Jon Baron's index with "incomplete ranks" and found nothing like this. If there is a package maintainer out there who is interested in using these functions, I would be happy to donate them. Jim __ 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] how to do interpolation
Yogesh Tiwari wrote: > Hello R Users, > > How to make a variable equidistance with time i.e. how to interpolate a > variable if it is not sampled at equal time interval. > Hi Yogesh, Don't know whether this will suit your purpose. I wrote it to enable color-coded plotting of highly variable data. If you pass your intervals as "yvec", it will linearly interpolate values of "xvec" so that the maximum difference between "yvec"s is "maxjump". If the "yvec"s are not multiples of "maxjump", you will get some smaller intervals. linterp<-function(xvec,yvec,interp=NA,maxjump=1) { if(is.list(xvec) && missing(yvec)) { yvec<-xvec$y xvec<-xvec$x } if(!missing(xvec) && !missing(yvec)) { newlength<-oldlength<-length(xvec) oldrows<-1:oldlength for(l in 2:oldlength) { # use the y values as a default if(is.na(interp[1])) ninserts<-ceiling(abs(yvec[l]-yvec[l-1])/maxjump) # assume interp is already a function of the successive x/y pairs else ninserts<-ceiling(abs(interp[l-1])/maxjump) oldrows[l]<-oldrows[l-1]+ninserts newlength<-newlength+ninserts-1 } xy<-list(x=rep(NA,newlength),y=rep(NA,newlength)) xy$x[oldrows]<-xvec # if xvec and yvec are not the same length, give up if(oldlength == length(yvec)) { xy$y[oldrows]<-yvec for(index in 1:(oldlength-1)) { ninterp<-oldrows[index+1]-oldrows[index] if(ninterp > 1) { xinc<-(xvec[index+1]-xvec[index])/ninterp yinc<-(yvec[index+1]-yvec[index])/ninterp for(istep in 1:(ninterp-1)) { xy$x[oldrows[index]+istep]<-xy$x[oldrows[index]+istep-1]+xinc xy$y[oldrows[index]+istep]<-xy$y[oldrows[index]+istep-1]+yinc } } } return(xy) } else cat("xvec and yvec must have the same length!\n") } cat("Usage: linterp(xvec,yvec,interp=NA,maxjump=1)\n") } Jim __ 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] NAs in indices
Muenchen, Robert A (Bob) wrote: > Hi All, > > I'm fiddling with an program to read a text file containing periods that > SAS uses for missing values. I know that if I had the original SAS data > set instead of a text file, R would handle this conversion for me. > > Data frames do not allow missing values in their indices but vectors do. > Why is that? A search of the error message points out the problem and > solution but not why they differ. A simplified program that demonstrates > the issue is below. > > Thanks, > Bob > > # Here's a data frame that has both periods and NAs. > # I want sex to remain character for now. > > sex=c("m","f",".",NA) > x=c(1,2,3,NA) > myDF <- data.frame(sex,x,stringsAsFactors=F) > rm(sex,x) > myDF > > # Substituting NA into data frame does not work > # due to NAs in the indices. The error message is: > # missing values are not allowed in subscripted assignments of data > frames > > myDF[ myDF$sex==".", "sex" ] <- NA > myDF > Hi Bob, What happens is that you don't get FALSE when you ask if something==NA, you get NA. However, if you use the "which" function, it cleans up the NAs for you and the result of that should do what you want. myDF[which(myDF$sex=="."),"sex"]<-NA Jim __ 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] plotting
yoo wrote: > Hi, let's say I have data > > x = c(1, 2, 10, 12) > y = c(100, -20, 50, 25) > > if I go plot(x, y), then the default x-axis range goes from 1 to 12. Is > there a way to change it so that the axis looks like: > > |-|-|-| > 1 2 10 12 > > This doesn't seem reasonable but let's say I want to plot intraday graph > with axis.POSIXct, my data is only from 8:30 to 4 every day and I have these > data for days.. i don't want to see a straight line every night.. Is there a > way I can do this? > Hi yoo, Have you looked at gap.plot (plotrix)? Jim __ 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] Automatic anchors for text boxes
Yves Moisan wrote: > Hi All, > > I'm struggling to add text automatically to plots. I have a series of > scatterplots that I have stored in a script because the underlying data > changes often and the plots need to be regenerated. I use the scatterplot > function (defined in Rcmd, I believe). When one of the variables is a > factor, a boxplot is drawn over the scatter of the other variable. In the > case where x is a factor with 10 values, I'll see 10 vertical boxplots. So > far, so good. > > I was asked to show other stats on top of those scatterplots, e.g. mean, > number of observations, etc. I can find those values, but the problem is I > don't know how to put them on the plot, given I don't want to look at each > plot one by one and manually identify the locations where I need to add the > text. I was wondering if something like a pseudo label (I want to keep the > original axis labels) existed that could be used to anchor a text box ? Or > maybe a semi-manual approach where I could offset such a pseudo-label > position along the y axis? Since I know the size of my resulting jpegs, I > could use a constant y offset for the text and they'd be aligned properly > along the x axis because they are labels. For the mean value, I could draw > a short horizontal line segment across the boxplot, but again I'd have the > problem of tying that line segment to specific x-axis values so they > intersect the right boxplot. Any clues ? > > On a related note, I've added regression lines, again by factor (thanks > scatterplot!), and was asked to write the regression equation in plain text. > I have between one and 7 lines on the plots, so again how could I > automatically tie a text box, this time to a specific regression line ? > Maybe that would be easier using a legend, but it would be nice to be able > to write the equation alongside the line. > > TIA Hi Yves, I may not understand exactly what you want, but spread.labels (plotrix) is useful for putting labels next to points that are spread out along one dimension. thigmophobe.labels puts labels next to points that are scattered around a plot. Jim __ 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] Excel
Rolf Turner wrote: > On 31/08/2007, at 9:10 AM, Antony Unwin wrote: > > >>Erich's more important point >>is that you need to speak the language of the people you cooperate >>with and often that language includes Excel. > > > So if the people you have to deal with are into astrology you should > learn astrology? > Yes, Rolf, if you want them to understand you. I once wrote a very successful parody of those astrology character profiles simply by borrowing an acquaintance's book and making dreadfully irreverent use of it. Jim __ 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] Single plot multiple levels in x?
Richard Yanicky wrote: > >One axis inside another, for example salary within state, > > > > >1-50 | 50 – 100 | 100+ | 1- 50 | 50 -100 | 100+ | … repeated >bins for salary > AL ! AR > …… more states Okay, I see what you mean. Try this: rydf<-data.frame( states=sample(c("NSW","QLD","VIC"),100,TRUE), salaries=2*(rnorm(100)+4)) nswdist<-hist(rydf$salaries[rydf$states=="NSW"],plot=FALSE, breaks=c(0,5,10,15))$counts qlddist<-hist(rydf$salaries[rydf$states=="QLD"],plot=FALSE, breaks=c(0,5,10,15))$counts vicdist<-hist(rydf$salaries[rydf$states=="VIC"],plot=FALSE, breaks=c(0,5,10,15))$counts library(plotrix) barp(c(nswdist,qlddist,vicdist),col=rep(2:4,each=3), main="Salary distribution by state", names.arg=rep("",9),ylab="Frequency") staxlab(at=1:9,labels=rep(c("0-50K","50-100K","100-150K"),3)) mtext(c("NSW","QLD","VIC"),side=1,line=3,at=c(2,5,8)) and it is a great boon to R-helpers to have data, even fake like the above. Jim __ 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] How to measure mode (central tendancy)
Raymond Balise wrote: > What is the name of the function to give me the mode (central tendancy) of a > numeric variable that can be negative? Hi Raymond, Have a look at Mode (note the capital letter) in the prettyR package. Jim __ 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] Simple Graph
amna khan wrote: > Hi Sir > > We use the function mpg() for ticks on axes. If we define more number of > ticks then each tick is not labeled. How to label each tick on axes? Hi Amina, The staxlab function in the plotrix package will display tick labels even if they would overlap on the standard axis display. Jim __ 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] breaking the x-axis and having two different x-axis labels
Georg Ehret wrote: > Dear R community, > I have two questions concerning barplots that I struggle to resolve: > > 1) How can I break (interrupt) the x-axis (e.g.: have it display values from > -100 to -90 and 90 to 100 only)? > I think you mean a horizontal barplot with a gap between -90 and 90. pyramid.plot (plotrix) doesn't quite do what you want, as the present version doesn't allow customized axis labels. The principle is the same as that used in gap.barplot, but the maintainer (me) didn't think that anyone would want to do this horizontally. If you are stuck I can add a feature or two... However, here's an unbeauteous hack. heights<-c(sample(-100:-91,5),sample(91:100,5)) barplot(c(heights[1:5]+90,heights[6:10]-90), horiz=TRUE,xaxt="n",xlim=c(-10,10)) axis(1,at=seq(-9,9,by=2), labels=c(-99,-97,-95,-93,-91,91,93,95,97,99)) axis.break(1,-0.1,style="gap") > 2) I overlay two horizontal barplots: one with negative values only and one > with positive values only: I would wish to mark the two datasets separately > on the x-axis (or some other way). If I use the legend I get a superposed > result... is there another way? > This sounds like a job for "axis", but I can't really picture what you describe. Do you want the negative bars starting from the right and going left and the positive ones starting from the left and going right? Or a vertical line in the center with the bars going in the usual directions? Jim __ 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] Recoding multiple columns consistently
Ron Crump wrote: > Hi, > > I have a dataframe that contains pedigree information; > that is individual, sire and dam identities as separate > columns. It also has date of birth. > > These identifiers are not numeric, or not sequential. > > Obviously, an identifier can appear in one or two columns, > depending on whether it was a parent or not. These should > be consistent. > > Not all identifiers appear in the individual column - it > is possible for a parent not to have its own record if its > parents were not known. > > Missing parental (sire and/or dam) identifiers can occur. > > I need to export the data for use in another program that > requires the pedigree to be coded as integers, increasing > with date of birth (therefore sire and dam always have > lower identifiers than their offspring) and with missing > values coded as 0. > > How would I go about doing this? > Hi Ron, Without the genealogical coding system for the output, I can only make a guess. It seems as though you are going from a series of records for which the index is the individual, followed by fields containing sire, dam and date of birth (perhaps not in that order). I think you want to transform this into a network (maybe hierarchical unless consanguinuity intervenes) with individuals coded as positive integers (and maybe some or all of the original information attached to those identifiers). At a guess, I would recode the birthdates as integers, preserving the order and including a rule for breaking ties. Assuming that you want an inverted tree for each individual, construct a linked list beginning with the individual with two pointers to the parents (their integer identifiers). Each parent has two links pointing to their parents, and so on. Whenever a pointer is zero, the linking stops. I don't know whether this can be represented in any of the tree diagrams in R, but it certainly could be coded. I think a bit more information for non-genealogists about the formats might elicit a more specific answer. > And a second, simpler related question, if I have a column with > n different values (may be strings or non-sequential integers) > identifying levels (possibly with repeated occurences), how > can I recode them to be sequential from 1 to n? > > I can solve both problems in fortran, so could use loops to > do it in R, but feel there should be quicker, more elegant, > "more R" solution. > sounds like "sort" Jim __ 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] fill circles
Cristian cristian wrote: > Hi all, > I'm an R newbie, > I did this script to create a scatterplot using the "tree" matrix from > "datasets" package: > > library('datasets') > with(trees, > { > plot(Height, Volume, pch=3, xlab="Height", ylab="Volume") > symbols(Height, Volume, circles=Girth/12, fg="grey", inches=FALSE, > add=FALSE) > } > ) > > I'd like to use the column Named "Height" to fill the circles with colors > (ex.: the small numbers in green then yellow and the high numbers in red). > I'd like to have a legend for the size and the colors too. > I did it manually using a script like that: > color[(x>=0.001)&(x<0.002)]<-"#41FF41" > color[(x>=0.002)&(x<0.003)]<-"#2BFF2B" > color[(x>=0.003)&(x<0.004)]<-"#09FF09" > color[(x>=0.004)&(x<0.005)]<-"#00FE00" > color[(x>=0.005)&(x<0.006)]<-"#00F700" > color[(x>=0.006)&(x<0.007)]<-"#00E400" > color[(x>=0.007)&(x<0.008)]<-"#00D600" > color[(x>=0.008)&(x<0.009)]<-"#00C300" and so on but I don't like to do it > manually... do know a solution... > Thank you very much > chris > Hi Chris, You can transform the numeric values in "Height" into colors using the color.scale function in the plotrix package. The color.legend function will allow you to get your legend. Jim __ 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] How to shade vertical bands in a graph?
del pes wrote: > Hello, > > I would like to draw vertical yellow bands in my graph, but could not find > how to do that in the documentation. > > I set up a page to show what I would like to achieve: > http://rstudent.blogg.de/eintrag.php?id=1 (the first picture was manually > colored with the Gimp). > Hi Delfina, For a one-off, I would use the rect function. fakedat<-0.985+rnorm(80)/100 plot(fakedat,main="My Striped Plot",type="n") rect(seq(5,75,by=10),par("usr")[3],seq(10,80,by=10),par("usr")[4], col="yellow") points(fakedat,type="b") abline(h=0.98) Jim __ 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] divided scatter plots
Caroline Nganga wrote: > I have a data set which contains two columns. The first column is a > list of countries, and the second column contains their political risk > ratings. I would like to create one large plot that contains 5 > different sections, each with a scatter plot. To clarify, I have > divided the countries into 5 groups. For each group (continent), I > would like to have the name of the continent on the x-axis, and points > representing countries and their risk rating on the y-axis. However, > I want all 5 scatter plots to be in one large plot. What function > should I use to do this? Also, is it possible to label each point? > thanks for any help! > Hi Caroline, If I understand your request, you might be able to use the axis.break function in the plotrix package. That is, you make one big plot with the points in five columns and then put gap style axis breaks between the columns. Here's a toy example: library(plotrix) prr.df<-data.frame(country=c("us","mx","ca","br","ar","pe", "ch","mn","in","nl","fr","es","na","mz","rw"), continent=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5), prr=rnorm(15)+4) plot(prr.df$continent,prr.df$prr,main="Political risk ratings", xlim=c(0.7,5.3),xlab="Continent",ylab="Risk rating",type="n") text(prr.df$continent,prr.df$prr,prr.df$country) axis.break(1,1.5,style="gap") axis.break(1,2.5,style="gap") axis.break(1,3.5,style="gap") axis.break(1,4.5,style="gap") Jim __ 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] Stacked Bar
Deb Midya wrote: > Hi R Users! > > Thanks in advance. > > I am using R-2.5.1 on Windows XP. > > I am trying to do a stacked bar plot, but could not get through the following > problem. The code is given below. > > 1. How can I provide 15 different colors for each method with 15 Rows? > > 2. How can I put the legend in a particular position (eg., in the top or > bottom or right or left)? How can I put legend using a number of rows (eg., > using two or three rows)? > Hi Deb, As you have probably noticed, the integer coded colors repeat too quickly for the number of colors you want. You can use the rainbow() function to generate colors like this: barplot(x,beside=FALSE,col=rainbow(nrow(x))) or there are lots of other color generating functions in the grDevices or plotrix packages. Here's how to get your legend in an empty space for your plot. There is also an emptyspace() function in the plotrix package that tries to find the biggest empty space in a plot, although it probably wouldn't work in this case. legend(0,1000,rownames(x),fill=rainbow(nrow(x))) Jim __ 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] Labelling certain points on the x-axis
squall44 wrote: > Hello, > > I created an empirical distribution function: > > x = c(1.6,1.8,2.4,2.7,2.9,3.3,3.4,3.4,4,5.2) > F2.5 <- ecdf(x) > plot(F2.5, > verticals= TRUE, > do.p = TRUE, > lwd=3, > ylab = "f(x)", > xlab = "x", > main = "Figur 2.5 Empirische Verteilfunktion", > xlim = c(1,5.5)) > abline(h= (0:5)*0.2) > > Now I would like to label the points on the x-axis where there is an > x-value: Given that you have two labels at the same point, you will have to stretch out your labels. I took out the X axis label to get enough room. library(plotrix) plot(F2.5, verticals= TRUE, do.p = TRUE, lwd=3, ylab = "f(x)", xlab = "", main = "Figur 2.5 Empirische Verteilfunktion", xlim = c(1,5.5)) abline(h= (0:5)*0.2) staxlab(at=x,labels=paste("X[",1:10,"]",sep=""),nlines=3,top.line=2) Jim __ 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] Interweaving cell entries from 2 columns
jenny wrote: > Hi, how do I interweave 2 columns of data into a single column? See > illustration below. Thx-jenny I have 2 columns of data Col1 Col21 > 2 3 45 6 7 89 10 I want to create a new > column with interlocking cell centries12345678910 Get the new Windows Live > Messenger! Try it! tddf<-data.frame(a=seq(1,9,by=2),b=seq(2,10,by=2)) as.vector(t(tdf)) Jim __ 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] multiple colors within same line of text
Andrew Yee wrote: > Hi, I'm interested in using mtext(), but with the option of having multiple > colors in the same line of text. > > For example, creating a line of text where: > > Red is red and blue is blue > > How do you create a text argument that lets you do this within mtext()? > You can do something like this with "text" and then use xpd=TRUE to use it outside the plot. I think it would be more fiddly trying to use "mtext". concat.text<-function(x,y,txt,col) { thisx<-x for(txtstr in 1:length(txt)) { text(thisx,y,txt[txtstr],col=col[txtstr],adj=0) thisx<-thisx+strwidth(txt[txtstr]) } } plot(0,xlim=c(0,1),ylim=c(0,1),type="n") ctext<-c("Roses are ","red, ","violets are ","purple") concat.text(0,0.5,ctext,col=c("black","red","black","purple")) Jim __ 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] vertically oriented color key in heatmaps
Rajarshi Guha wrote: > Hi, I have some data which I was plotting using image(). I wanted to > add a vertical color key to the plot and I found that heatmap.2 in > gplots does let me add a color key. However, I was thinking of a > vertical bar with the color range rather than the style that gplots > provides. > > Is there any package (or code snippet) that would let me add a > vertical color key to an image() or heatmap plot? > Hi Rajarshi, Have a look at color.legend in the plotrix package. Jim __ 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] Positioning text in top left corner of plot
Daniel Brewer wrote: > Thanks for the replies, but I still cannot get what I want. I do not > want the label inside the plot area, but in the top left of the paper, I > suppose in the margins. When I try to use text to do this, it does not > seem to plot it outside the plot area. I have also tried to use mtext, > but that does not really cut it, as I cannot get the label in the > correct position. Ideally, it would be best if I could use legend but > have it outside the plot area. > > Any ideas? > Hi Dan, Try this: plot(1:5) par(xpd=TRUE) text(0.5,5.5,"Outside") par(xpd=FALSE) Jim __ 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] Subject: Re: how to include bar values in a barplot?
Gabor Grothendieck wrote: > You could put the numbers inside the bars in which > case it would not add to the height of the bar: > > x <- 1:5 > names(x) <- letters[1:5] > bp <- barplot(x) > text(bp, x - .02 * diff(par("usr")[3:4]), x) > Indeed, the boxed.labels function makes this pretty easy. boxed.labels(bp,x-0.2*diff(par("usr")[3:4]),x) gives you the labels in a little white rectangle so that none are invisible. I also greatly enjoyed Ted's rebuttal of the "Bar charts are evil and must be banned" argument. If bar charts are appropriate for the audience, give 'em bar charts. One great way to turn off your customers is to tell them what they can and can't do with your product. Jim __ 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] saving output
Lynn Disney wrote: > I have a question about how to save the output of a logistic regression > model in some format (delimited, preferably) so that I can manipulate it > to make nice tables in excel. I have tried print, save, write, none seem > to do what I want them to. Does anyone have any ideas? > Hi Lynn, This is an interesting idea that might be useful in the prettyR package. You have just volunteered to be a test pilot. delim.table<-function(x,con="",delim="\t") { if(nchar(con)) { con<-file(con,"w") open.con<-TRUE } else open.con<-FALSE column.names<-names(x) if(is.null(column.names)) column.names<-colnames(x) have.col.names<-!is.null(column.names) row.names<-rownames(x) have.row.names<-!is.null(row.names) xdim<-dim(x) if(have.col.names) { cat(delim,file=con) for(col in 1:xdim[2]) cat(column.names[col],delim,sep="",file=con) cat("\n",file=con) } for(row in 1:xdim[1]) { if(have.row.names) cat(row.names[row],file=con) cat(delim,file=con) for(col in 1:xdim[2]) cat(x[row,col],delim,sep="",file=con) cat("\n",file=con) } if(open.con) close(con) } test.df<-data.frame(a=sample(0:1,100,TRUE),b=rnorm(100),c=rnorm(100)) delim.table( summary(glm(a~b*c,test.df,family="binomial"))$coefficients, con="test.csv") This output should import into Excel with no trouble (it does in OpenOffice Calc). Either use sink() or specify a filename as in the example. Jim __ 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] Selectively shading areas under two density curves
Ian Watson wrote: > Dear Listers, > > I am drawing a plot of two density curves, for male and female incomes. I > would > like to shade/hatch/color (whatever) the areas under the curves which are > distinctive for each gender. This is the code I have tried so far: > > > m <- density(topmal.d$y, bw = "sj") > f <- density(topfem.d$y, bw = "sj") > par(mfrow = c(1,1)) > plot(x = c(0,400), y = c(0,0.02), type = "n", > bty = "l", xlab = "Annual earnings (in $thousands)", ylab = "Density") > polygon(m, col = "blue", border = "blue", density = 20, angle = -45) > polygon(f, col = "red", border = "red", density = 20, angle = 45) > > > Without the data I realise you may not be able to see my goal. But basically > the > m density and the f density overlap for most of the plot, but areas "bulge" > out on the left and right of the overlapped area. What I'm wanting to do is > shade/hatch/color etc these areas which are unique to each density, that is, > which are outside the overlapped area. > > My code is successful at hatching the bulging areas, but leaves me with a > double > hatched area for the overlap, which is distracting. If I could turn this > double > hatched area white, that would achieve my goal, though ideally I would like > to > be able to specify something like "shade only areas under the m density curve > which are not also under the f density curve (and shade only under the f > density > curve those areas not under the m density curve". > Hi Ian, Once you get used to the vagaries of "density" output, this isn't too hard, as you only have one crossing. I think this gets you what you want: minc<-rnorm(1000,mean=65000,sd=15000) finc<-rnorm(1000,mean=55000,sd=15000) m <- density(minc, bw = "sj") f <- density(finc, bw = "sj") plot(m$x,m$y,main="Male vs female income distribution", xlab="",ylab="Density",type="l",xaxt="n") library(plotrix) axis.mult(1,at=c(0,2,4,6,8,10,12),mult=1000, labels=c("0","20","40","60","80","100","120"),mult.label="Annual income/1000") lines(f$x,f$y) fontop.end<-max(which(f$y>m$y)) xend<-length(f$x) polygon(c(f$x[1:fontop.end],rev(m$x[1:fontop.end])), c(f$y[1:fontop.end],rev(m$y[1:fontop.end])),col="red") fontop.end<-fontop.end+1 polygon(c(f$x[fontop.end:xend],rev(m$x[fontop.end:xend])), c(f$y[fontop.end:xend],rev(m$y[fontop.end:xend])),col="blue") Jim __ 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] - round() strange behaviour
(Ted Harding) wrote: > ... > Thus "always up" or "always down" means that the difference between > rounded numbers is always the same as between the unrounded numbers > which for other methods the differences can differ by 2.0. > This may or may not matter, but it is something to think about > when choosing a rounding method. > Ah, but Ted, this is why, as I remarked in a private message to the original poster, we were also taught never to round until the final result. Had I not had a rather extended debate with an engineer who apparently thought that one could get away with successive rounding, I would not be so sensitive on the issue. Jim __ 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] shadow between two lines in plot()
Ding, Rebecca wrote: > Dear R users, > > I used the following code to draw a scatter plot. > > plot(x,y,type="n") > points(x,y,pch=1) > > And then I used the abline functions to draw two lines. I want to add > the shadow between those two lines. > > abline(h=200) > abline(h=300) > > Any suggestions? > Hi Rebecca, Have a look at polygon.shadow in the plotrix package. You can display a shadow-like figure based on any polygon. Jim __ 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] "Cut marks" on a plot's y-axis to indicate it is a truncated axis
David Lloyd wrote: > Hi, > > I've plotted a Kaplan-Meier curve but the curves only range from 0.7 to > 1 on the y-axis. Therefore I have used: - > > ylim=c(0.7,1) > > [although I think convention dictates that you plot 0.5 to 1 to show the > median? A few papers I've read have done this]?? > > BUT, I would like a symbol like // (but rotated 90 degrees) to indicate > that the y-axis has been truncated. I'd need to be able to specify > exactly where on the axis to put the symbol as well. > > I couldn't find anything under "par" or "plot" for doing this > Hi David, Try looking for axis.break in the plotrix package. Jim __ 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] Average plan
Nok Noy wrote: > Hello, > > I'm looking for a method to compute an average plan from 4 or 5 point in an > cartesian space. I'm sure It can be done using a less-square method but > maybe it a function already exist in R system to get this plan. > Can somebody help me to solve this problem (I'm looking on the net for hours > but didn't find anything realy satisfiying me) Hi Nok, I haven't seen any answers to your question, and this may be due to the fact that no one knows what you are asking. Do you mean that you want to define a _plane_ that is the best fit to more than three points in a three dimensional system? Jim __ 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] How to add circular text for a graph with concentric circles
[EMAIL PROTECTED] wrote: > Dear R experts, > > I am plotting the population of students who live in a city, and in > successive circular bands made of the contiguous districts that surround > the city. This is a stylized figure, where I specify the area of each > successive circle based on the cumulative population of students. I want > to compare two sets of concentric circles across different populations - > such as 'All students' and 'Private students' (those attending private > school) by using the same colours and the same dimension of the outer > circle. I have attached the .pdf file with the output, and the R code to > generate the first set of circles. > > I would appreciate any tips about how to rotate the text label that marks > each concentric circle (except the central circle) to be curved around the > circle, located in the middle of each band, thus following the circle > instead of being horizontal, as I have it now. > Hi Suhas, This is kind of rough, being rejigged from an old piece of Postscript code that I wrote to get text in an arc. You specify the text and whatever else is needed as in the following example: arctext<-function(x,center=c(0,0),radius=1, midangle=pi/2,stretch=1.1,cex=1,...) { oldcex<-par("cex") par(cex=cex) xwidth<-strwidth(x)*stretch startpos<-midangle+xwidth/(radius*2) xvec<-strsplit(x,"")[[1]] xwidths<-rep(mean(stretch*strwidth(xvec)),length(xvec)) arcpos<-startpos-cumsum(xwidths) for(i in 1:length(arcpos)) text(center[1]+radius*cos(arcpos[i]),center[2]+radius*sin(arcpos[i]), xvec[i],adj=c(0.5,0.5),srt=(arcpos[i]-midangle)*180/pi) par(cex=oldcex) } plot((1:5) arctext("bendy as a bloody piece of spaghetti",center=c(3,3)) radius is obviously the radius of the arc, midangle is where you want the center of the text, stretch is how much to stretch the text to make it look nice and cex is the expansion factor. You will probably notice that I kludged the spacing by making it monospaced. I'll have a try at getting proportionally spaced text to work right when I get a chance. Jim __ 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] mfrow is ignored by some plots
Prof Brian Ripley wrote: > I'd ask the plotrix maintainer to fix his code! > > radial.plot saves and restores all the par() values, including mfrow and > mfg. When you do par(mfrow=c(2,2)) the plot position is reset to the > bottom right, and the next plot will advance to the top left (but > par(new=TRUE) negates that). > > Please restore only the par values you have changed, not all the > no.readonly ones. That values can be set does not make it a good idea > to do so. > Thank you Prof. Ripley, an erudite and functional answer as usual. Jim __ 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] mfrow is ignored by some plots
Hi all, I was just informed that the plots in the radial.plot family in the plotrix package do not plot correctly when using mfrow or mfcol to subdivide the plot window. I found one related message, an answer from Deepayan Sarkar to a question about lattice graphics, but that shed no light on this problem. If I invoke par(mfrow=c(2,2)) and run radial.plot a few times, the plots appears in the upper left corner. _Sometimes_ the second plot appears in the upper right corner once, but then returns to the upper left. If I invoke par(new=TRUE), the plots appear in the lower right corner. For instance, the following just keeps writing the plots in the upper left. par(mfrow=c(2,2)) radial.plot(rnorm(7),0:6,line.col="red",lwd=2) radial.plot(rnorm(7),0:6,line.col="red",lwd=2) radial.plot(rnorm(7),0:6,line.col="red",lwd=2) radial.plot(rnorm(7),0:6,line.col="red",lwd=2) If I then enter: par(new=TRUE) and repeat the plots, they all accumulate in the lower right. I think this may have something to do with the calls to points or lines or symbols within radial.plot, but I could find no information on this in the help for plot, par, or several other pages. Any clues? Jim __ 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] Missing value in circ.mean and polar.plot
Gagnon,Francois [SteFoy] wrote: > Hi, > > I try to compute circular means for a matrix with NAs, but the function > "circ.mean" return only means for lines with complete values and do not > accept "na.omit=T" or "na.rm=T", or "na.action=na.omit", or "na.fail=T". > Also, I try to use "polar.plot" of the package poltrix with the same matrix, > but angles are not display because of many NAs. > Does any one know how what should be the right NA action to get results in > these two cases ? > Hi Francois, For one thing, you should be using radial.plot, as the angles are in radians, not degrees. However, your data shows up a couple of problems with radial.plot that I will fix. I'm currently fixing some minor (I hope) problems with plotrix v2.2-3 and this should turn up on CRAN in the next few days. I'll see if I can get radial.plot to produce the sort of plots you are seeking. Thanks for finding the problem. Jim __ 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] Text with differents colors in a plot / Detecting if text exists
Maja Schröter wrote: > Hi everybody, > > I want to write some text in a plot. > > That's simple I know. But I want to make use of different colors. > > Eg. text(x,y,paste("Sunderland","high")). > > Then Sunderland should be black and "high" red. > > Has anyone an idea? > > By the way. I'm looking for a function or something similar, that can check > whether there is text in some regions on the plot. > Because I don't want to overwrite an existing text with a new one. > Hi Maja, For your first question: text(c(9,9),c(5,5),c("Sunderland","high"), pos=c(2,4),offset=0.2,col=c("black","red")) i.e., don't form a single string so that you can specify different colors and positions for the two words. For the second one, I am about to upload a new version of the plotrix package that contains a function named "emptyspace". This tries to find the largest rectangle on a plot that has nothing plotted within it. Jim __ 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] The results of your email commands
dimple thyagarajan wrote: > ... > Building a website is a piece of cake. But sending an email is another matter altogether. Jim __ 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] character string to name
Jim Lemon wrote: > Hi folks, > > I thought I recalled a request for turning a character string into an > object name as in: > > x$as.name("y")<-1:4 > ... Thanks to those who replied to this eminently dumb question. OT: I put this down to the Euthermic Model of Cognitive Efficiency. This model, recently developed in Sydney, Australia, proposes that cognitive efficiency is maximized at the most comfortable ambient temperature for the thinker. Thus after riding home in the cold Sydney rain last night, I was unable to think of the simplest answer: names(x)<-"y" until I had gone to bed and warmed up. Then I awoke in the early morning and thought of Gabor's suggestion: x[["y"]]<-... I felt compelled to arise and publish this amazing theory, that not only explains why the rate of intellectual and technical innovation is greatest in the temperate climes, but more importantly, gives me an excuse for asking the question. Jim __ 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] character string to name
Hi folks, I thought I recalled a request for turning a character string into an object name as in: x$as.name("y")<-1:4 OR x<-data.frame(as.name("y")=1:4) However, as.name and a few other uninformed attempts didn't even come close. A search of "character to name" produced no helpful functions. This isn't a very urgent request, but if anyone knows some trick to perform this transformation, I would like to hear about it. Thanks. Jim __ 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] color scale in rgl plots
David Farrelly wrote: > Hello, > > I'm trying to make a 3d plot using rgl in which the size and color of > each point corresponds to certain attributes of each data point. The color > attribute, let's call it X, is scaled to go from 0 to 1. The > rainbow(64,start=0.7,end=0.1) palette is perfect for what I want but I > don't know how to take that palette and pick a color from it based on > the value of X for a given data point. I'm fairly new to R and any > suggestions would be greatly appreciated. > > Here's what I do - it's how to do the color mapping that has me stumped. > > plot3d(th1,ph,th2,type='s',size=wd1,col=(rp1,0,0,1),cex=2,ylab=NULL,xlab=NULL,zlab=NULL,xlim=c(0,1),ylim=c(0,2),zlim=c(0,1),box=TRUE,axes=FALSE) > > I have also tried the more obvious col = rgb(a,b,c,d) where a,b,c,d are > functions of X but I can't manage to come up with a nice looking color > scale. > Hi David, You could check out color.scale in the plotrix package, which does just this. Jim __ 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] Please help with legend command
Smith, Phil (CDC/CCID/NCIRD) wrote: > Hi R-ers: > > I'm drawing a plot and have used different line types (lty) for > different race/ethnicity groups. I want a legend that explains what line > types correspond to the different race/ethnicity groups. I used the > following code: > > > legend( 1992 , 42 , c("Hispanic" , "non-Hispanic white (NHW)" , > "non-Hispanic black" , "AI/AN" , "Asian" ) , lty=1:5 ,cex = .6 , bty='n' > ) > > Guess what? The legend "box" was so narrow that the line types that show > up in that legend box look essentially the same, because they are short. > I.e, although a line type might be a long dash followed by a short dash, > only the long dash shows up in the box. The consequence of this is that > the race/ethnic group that corresponds to the line type that is only a > long dash cannot be distinguished from the legend. > > How do I stretch that legend box out so as to allow lty to draw longer > line segments? > Hi Phil, A quick hack is to get a copy of the function: sink("newlegend.R") legend sink() Get the file into a text editor and first get rid of the at the bottom, then change line 161 to: w0 <- w0 + (4 + x.off) * xchar and line 212 to: seg.len <- 4 source the new function: source("newlegend.R") and your line segments will be twice as long. Jim __ 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] Plotting very skewed data in barplot
Dr. med. Peter Robinson wrote: > Dear R'ers, > > I would like to use barplot or a similar function to plot data > demonstrating the distribution of the length of a kind of conservation in > about 25000 DNA sequences. My data look like this: > ... > > Therefore, I would like to show the column representing 0 (with 19936 > sequences) "cut" so it doesn't dominate the rest of the plot. Also, > starting from about 10 sequences, I would like to group the rest of the > sequences into groups of 5 each (for instance, 10-15, 16-20, 21-25 etc). > Hi Peter, Have a look at gap.barplot in the plotrix package. I would suggest something like this: gap.barplot(y,c(500,19800),main="Skewed distribution", yaxlab=c(200,400,19900),ytics=c(200,400,19900)) where y is the right column of your data. Jim __ 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] Combine graphical and textual output
Dieter Vanderelst wrote: > Hi, > > I would like to know whether anybody knows a simple way to combine > textual and graphical output in R. > > A typical analysis produces textual output (e.g. model fits) and plots > in R. I would like to know whether R has the possibility of combining > these into a single 'report' or output. An example of a program that > does this is SPSS. After running the analysis you have a combination of > textual output (tables) and plots that are easy to print and distribute. > > I know of the possibility to embed R code into LATEX (using Sweave), but > I wouldn't call this quick since a lot of coding will go into writing > the Sweave file. > > Any other suggestions? > And to further complicate the issue, you could look at the htmlize and R2html in the prettyR package, which allows you to run an R script and produce HTML output. Jim __ 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] Plots from categorial data
Christoph Krammer wrote: > Hello everybody, > > Since my first message was caught by the spam filter, I just try to do it > again: > > I want to use R to generate plots from categorial data. The data contains > results from OCR scans over images with are preprocessed by different image > filtering techniques. A small sample data set looks as following: > > >>data <- read.csv("d:/tmp_da/sql_data/filter_d_tool.csv", header=T) >>data > > ocrtool filter_setting avg.hit. > 1 FineReader2x10.383 > 2 FineReader2x20.488 > 3 FineReader3x20.268 > 4 FineReader3x30.198 > 5 FineReader4x30.081 > 6 FineReader4x40.056 > 7gocr2x10.153 > 8gocr2x20.102 > 9gocr3x20.047 > 10 gocr3x30.052 > 11 gocr4x30.014 > 12 gocr4x40.002 > 13 ocrad2x10.085 > 14 ocrad2x20.094 > 15 ocrad3x20.045 > 16 ocrad3x30.050 > 17 ocrad4x30.025 > 18 ocrad4x40.009 > > > I now want to draw a plot with the categories (filter_setting) as X axis, > and the avg_hit as Y axis. There should be lines for each ocrtool. > > But when I draw a plot, the resulting plot always contains bars, even if I > specify type="n". > >>plot(data$filter_setting, data$avg.hit., type="n") > > > When I only plot the categories, without data, there appear strange grey > (but empty) boxes. > >>plot(data$filter_setting, type="n") > > > Who do I get a clean white box to draw the different lines in? > Hi Christoph, How about this? plot(as.numeric(krammer$filter_setting[1:6]),krammer$avg_hit[1:6], type="b",col=2,ylim=c(0,0.5),main="OCR performance", xlab="Filter setting",ylab="Average hits",axes=FALSE) points(as.numeric(krammer$filter_setting[7:12]),krammer$avg_hit[7:12], type="b",col=3) points(as.numeric(krammer$filter_setting[13:18]),krammer$avg_hit[13:18], type="b",col=4) box() axis(1,at=1:6,labels=c("2x1","2x2","3x2","3x3","4x3","4x4")) axis(2) Jim __ 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] Repeat if
Birgit Lemcke wrote: > Hello, > (Power Book G4, Mac OS X, R 2.5.0) > > I would like to repeat the function range for 85 Vectors (V1-V85). > I tried with this code: > > i<-0 > > repeat { > + i<-i+1 > + if (i<85) next > + range (Vi, na.rm = TRUE) > + if (i==85) break > + } > > I presume that the Vi is wrong, because in this syntax i is not known > as a variable. But I don´t know how to say that it is a variable here. > Would be nice if somebody could help me. > Perhaps I´m thinking too complicated and there is an easier way to do > this. > Hi Birgit, This may be what you want: for(i in 1:85) print(do.call("range",list(as.name(paste("V",i,sep="") Jim __ 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] Looking for parallel functionality between Matlab and R
El-ad David Amir wrote: > I'm slowly moving my statistical analysis from Matlab to R, and find myself > missing two features: > > a) How do I mimic Matlab's 'hold on'? (I want to show several plots > together, when I type two plots one after the other the second overwrites > the first) > b) How do I mimic Matlab's 'axis'? (after drawing my plots I want to zoom on > specific parts- for example, x=0:5, y=0:20). > I think what you want for a) is par(ask=TRUE). There have been a few discussions of zooming on the help list - see: http://stats.math.uni-augsburg.de/iPlots/index.shtml for one solution. Jim __ 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] how to plot this?
Weiwei Shi wrote: > Hi, there: > > Suppose I have a couple of data.frames and each one has five columns > (one for x-axis, two for y-axis and two for std of y's.) There is > another dimensions (besides x and y) which is continuous. My question > is, how to plot such series of data frames in one plot (thus, > 3-dimensional plot) AND multiple 2-D plots. I am not familar with R's > plotting utilities. > Hi Weiwei, Maybe color2D.matplot for the 2D plots, setting par(mfrow...) appropriately. I have just uploaded a new version of plotrix in which color2D.matplot will handle NAs appropriately, doing such things as upper or lower triangles of matrices. Look for version 2.2-2 when it pops up on CRAN. Jim __ 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] Encircling a text in a plot
Maja Schröter wrote: > Hello everyone, > > I want to write something in a plot with text or something similar, e.g. > text(x,y,"something") but I want to encircle it by a box as in a legend. > > I have absolutely no idea how this could work. > Hi Maja, Have a look at boxed.labels and textbox in the plotrix package. Jim __ 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] how to create cumulative histogram from two independent variables?
Jose Borreguero wrote: > Hi all, > I am extremely newbie to R. Can anybody jump-start me with any clues as to > how do I get a cumulative histogram from two independent variables, > cumhist(X,Y) ? > -jose > Hi Jose, Is this something like you want? var1<-sample(1:10,100,TRUE) var2<-sample(1:10,100,TRUE) barplot(rbind(hist(var1,plot=FALSE)$counts,hist(var2,plot=FALSE)$counts)) Jim __ 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] names over names
elyakhlifi mustapha wrote: > Hello, > I wonder if it's possible to put names above column names. > Do you know if it's possible? If you mean something like this: Weekdays Monday Tuesday Wednesday Thursday Friday and you want it to be part of the data frame: attr(mydf,"supername")<-"Weekdays" This will not just appear when you print the data frame, you would have to access the "supername" like this: attr(mydf,"supername") [1] "Weekdays" However, I suspect that whatever you are trying to accomplish can be done in a more straightforward way. Jim __ 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] triangle contour plots
Robin Hankin wrote: > Suppose I have three numbers p1, p2, p3 with > 0 <= p1,p2,p3 <= 1 and p1+p2+p3=1, > and a function f=f(p1,p2,p3) = f(p1,p2,1-p1-p2). > > How to draw a contour plot of f() on the p1+p2+p3=1 plane, > that is, an equilateral triangle? > > Functions triplot(), triangle.plot(), and ternaryplot() give > only scatterplots, AFAICS > Hi Robin, I was all ready to say that triax.plot could do what you want if I added a "type" argument, but found that for some reason both "points" and "lines" are only reading the first color in a vector. If I send more than one color to either function, I only get the first one. If I can sort this out, it's easy to use triax.plot to do what you want (unless, of course, you are satisfied with lines of one color). Jim __ 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] Readline
Antje wrote: > Hello, > > I also have problems to get to run the following lines. If I run the > block instead of every single line, it simply does not wait for the input. > Can anybody help me? > > > pos_name <- readline("Please type: ") > > r <- substr(pos_name, 1,1) > c <- substr(pos_name, 2,nchar(pos_name)) > > > Hi Antje, What you seem to be doing is pasting the lines into the R window. The second line looks like the input line that the first line is expecting, and if you remove the empty line, you will see that pos_name has been assigned the text of the second line. If you put these lines into a text file and then use "source" to read it, it works as I think you expect. Jim __ 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] R help
scott flemming wrote: > Hi, > > I wonder whether R can finish the following project: > > I want to make a chart to represent 10 genes. Each gene has orientation and > length. Therefore, a gene can be represented by arrows. > > Can R be used to draw 10 arrows in one line ? > Hi Scott, Maybe the feather.plot function in the plotrix package is what you want. Jim __ 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] Filled step-function?
Beate Kowalczyk wrote: > Hello, > > I'd like to generate a filled step-function in R as you can see in the > attachement (image is generated by grapher, but I need a freely > available alternative). The problem is, that I don't know, how to fill > it up. My code right now looks like this: > > pH <- c(0,6.1,6.1,6.3,6.6,7.3,0) > Tiefe <- c(0,0,10,40,80,120,10) > plot(pH,Tiefe,type="s",main="Tiefenfunktion pH",ylim=c(120,0),xlim=c(0,23)) > Hi Beate, If I understand this, you want the steps to be converted into a polygon and displayed instead of the plot "step" display. You also want the y axis reversed. This might do what you want: stepfun.polygon<-function(x,y,miny=min(y),col=NULL,...) { plot(x,y,ylim=c(max(y),min(y)),type="n",...) polyx<-c(x[1],rep(x[2:length(x)],each=2),x[1]) polyy<-c(rep(y,each=2)) polygon(polyx,polyy,col=col) } Note that you will probably only want the observed values of x and y, as the zeros on the end produce an unwanted spike in the polygon. Jim __ 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] So long, concord
Hi R-users, In the interest of reducing the duplication of functions and multiplication of packages on CRAN, I will no longer be upgrading the concord package, and will in time remove it. Matthais Gamer has offered to host the following functions in the "irr" package: kripp.alpha (Krippendorff's alpha) mcnemar.mh (McNemar marginal homogeneity test) rater.bias (test of bias between two raters) stuart.maxwell.mh (Stuart-Maxwell marginal homogeneity test) The "quest.reliability" function will move to Harold Doran's "MiscPsycho" package, although perhaps with some alterations. If any package maintainers are interested in a function to compute Page's Trend Test, let me know. Rather than start up an "R-bay" for functions, I will donate it free to a good home. Jim __ 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] Representing a statistic as a colour on a 2d plot
mister_bluesman wrote: > Ive been getting the color.scale function to work. However, I really need to > know is that if i have values: 0.1 0.2, 0.3, 0.4, 0.5, for example, how I > can plot these using colours that would be different if the contents of the > file were 0.6, 0.7, 0.8, 0.9 and 1.0. Using color.scale scales them so that > they differ, but only relative to each other, rather than taking the actual > value and converting them to some unique colour/colour intensity. > > Many thanks > There are a couple of ways to go about this. If you know that there are say ten possible values, you can use the color.gradient function to assign ten colors across a particular range. Then you would have to map the colors to the numbers (I would do something like creating a two element list of the sorted unique numbers and the colors. Then assign the color vector for the plot from this list.) Note that both color.scale and color.gradient are aimed at producing colors that visually represent some range like cold(blue) to hot(red). If you just want to get 20 easily discriminated colors and assign them to values, you might be better off with ColorBrewer. Jim __ 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] Representing a statistic as a colour on a 2d plot
mister_bluesman wrote: > Hello. > > I have a 2d plot which looks like this: > > http://www.nabble.com/file/8242/1.JPG > > This plot is derived from a file that holds statistics about each point on > the plot and looks like this: > > abc d e > a00.4980.4730.524 0.528 > b 0.498 0 0 0 0 > c 0.473 0 0 0 0 > d 0.524 0 0 0 0 > e 0.528 0 0 0 0 > > However, I have another file called 2.txt, with the following contents: > > a b c d e > 0.5 0.7 0.32 0.34 0.01 > > What I would like to know is how do I convert these values in 2.txt to > colours or colour intensities so that the x's in the diagram above can be > colour coded as such. Yo bluesman, check color.scale in the plotrix package, cat it'll color your points to the values they're at Jim __ 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] Polar graph of time and tide
Alan E. Davis wrote: > I have been trying to visualize times of lowest tides, month by month. > I have tide predictions with times either in unix time or a text > format, and heights in feet or meters. I had been able to derive the > clock times of each prediction. I would now like to graph this data > with points showing heights as "r" and times as "theta", from to > 2355. There is a seasonal component: I am interested in displaying > times of lowest tides in particular. > > I am sure this is so simple as to burden those on the list; I however > have spent two evenings trying to figure out how to use polar.plot, > and I'm not sure that's the best way to do this. May I request some > advice? The docs with polar.plot are not complete, I fear. > > Thank you, begging for your indulgence, > Hi Alan, Earl Glynn's advice is spot-on if you are trying to map tides onto the diurnal cycle. However, I get the impression that you want an annual cycle. If this is the case, it is probably best to go to the underlying function, radial.plot. Here is an example with some imaginary tides. lowtide<-sin(seq(1:12)+sin(seq(1,24,by=2)/10)) lowtide<-rescale(lowtide,c(0,2355)) month.abbr<-c("jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec") radial.plot(lowtide,labels=month.abbr,rp.type="s") This plots time of lowest tide in a month as a symbol at a radial distance proportional to the 24 hour time of day. As you can see from running the example, the months of the year are displayed around the circumference of the plot. One annoyance is that the hours are displayed as 0-2500. As "pretty" handles that, you would have to set show.radial.grid to FALSE and manually draw the desired grid (a pain, but not impossible). You could also place the symbols at the position in the month of the lowest tide by specifying radial.pos instead of letting the function spread them out evenly. If you want to overlay a number of years, x should be a matrix and point.col can be chosen so that each year has a different color. I would like to know of any deficiencies in the docs, as while I think I know what I'm talking about, it is you out there who have to understand it. Jim __ 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] to draw a smooth arc
(Ted Harding) wrote: > This thread prompts me to ask about something I've > been pondering for a while, as to whether there's an > implementation somewhere ticked away in the R resources. > > So far, people have been responding to the original query > in terms of increasing the numbers of points, and joining > these by lines. > > However, if you're using PostScript output, you can draw > really smooth curves by exploiting PS's "curveto" operator. > This draws a cubic-curve segment in the following way: > > ... > Anyway. The Question: is there a general function for the > above kind of smooth curve-drawing? > Hi Ted, My experience with this some years ago was in anti-aliasing visual stimuli presented on a PC monitor. The intended line was calculated pixel by pixel and the each pixel that the line touched was assigned a value based on a sawtooth function. The peak of the function was always exactly on the intended line and the luminance of the pixel was a linear function of the distance of its center along a perpendicular to the line. We used the width of a pixel as the lateral extent of the function with adequate success. The lines appeared smooth until the viewer could resolve the individual pixels. Wider lines used a trapezoidal distribution of luminance with the same slope on the limbs. I must note that we did not have to create our stimuli in real time, and this method might be too slow. However, I am fairly certain that if the function knew about the characteristics of the output device, one could base a curveto function on this. Jim __ 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] to draw a smooth arc
Paulo Barata wrote: > Dear R-list members, > > I would like to draw a smooth arc. I can draw an arc > parametrically, but this produces an arc too coarse, > even allowing for different increments in sequence t > in the example below. Function "symbols" (graphics) does > produce a smooth circle, but it cannot produce an arc. > > Please see the following example, drawing complete circles: > > plot(-5:5,-5:5,type='n') > ## draws circle with function symbols (package graphics) > ## - inner circle is very smooth: > symbols(0,0,circles=2,add=TRUE) > ## draws circle parametrically - outer circle is too coarse: > pi <- 4*atan(1) > t <- seq(0,2*pi,0.02) > lines(4*cos(t),4*sin(t)) > > Package "plotrix" has a function "draw.arc", but arcs produced > with this function are also either too coarse or too polygonal, > depending on the number of polygons used to approximate the arc. > > Is there a way to harness the characteristics of function > "symbols" (graphics) to draw a smooth arc, not just a complete > circle? > Hi Paulo, I may be misunderstanding you, but have you tried to increase the number of segments in the arc using the "n" argument? draw.arc(1,1,1,n=100) Jim __ 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] Can a hyperlink be placed, thorugh R programming, on a graph?
Aldi Kraja wrote: > Hi, > If I use > > x<-1:10 > y<-rnorm(10,0,1) > ### pdf(file="c:\\aldi\\test.pdf") > plot(x,y) > segments(x,y,x+2,y+2) > segments(x,y,x+0.5,y+0.5,col=3) > ### dev.off() > ### q() > > Is there a way that I can imbed in the graph plot for each point defined > by x to x+0.5 and y to y+0.5 (and colored in green) a different hyperlink? > > For example point one (together with the green tail) will have the > hyperlink: www.r-project.org; point 2 with the link www.google.com; > point 3 with the link www.yahoo.com etc. > > So in general, can the graph be manupulated within R? > Hi Aldi, In HTML, the way to do this is usually known as an image map. Here is one way to accomplish this. png("aldi.png") plot(x,y) segments(x,y,x+2,y+2) segments(x,y,x+0.5,y+0.5,col=3) dev.off() After generating the image in a format that will display on an HTML page, create the page. HTML image map demo Click on one of the points to go to another URL http://www.r-project.org";> http://www.google.com";> http://www.yahoo.com";> Now if you point your browser at that HTML page, you should be able to click on the first three points and be transferred to the URLs in your example. Doing this in PDF should be pretty similar, but I don't know how to write PDF code. However, if you look at the code in either the R2HTML package or the prettyR package, you can see how this could all be generated in R. Jim __ 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] help
Natalie O'Toole wrote: > Hi, > > Would anyone know how to calculate the modal value of LeafArea? > > Thank-you very much!! > > Nat > > __ > > Hi all, > > I have 2 questions: > > 1)How do I calculate the mean on an imported txt file? I've imported the > file below and that's what it looks like imported. How do I then calcuate > the mean, median, or mode on the column LeafArea using the desktop R > package? > Hi Nat, Try this: leaf.df<-read.table("leafdata.csv",header=TRUE) library(prettyR) describe(leaf.df) Mode(leaf.df$LeafArea) Jim __ 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] convergence
rach.s wrote: > hie.. > how can i write a loop that makes algorithm keeps repeating until a solution > is converged?do i use a for loop? i know that we can use for loop to ask for > a number of repetitions, but how to use it to ask the algorithm to keep > repeating until a solution is converged? gregory.liebniz<-function(tol=0.0001) { pi.diff<-1 iter<-0 numer<-1 last.pi<-0 pi4<-0 while(pi.diff > tol) { pi4<-pi4+numer/(2*iter+1) this.pi<-pi4*4 pi.diff<-abs(this.pi-last.pi) last.pi<-this.pi iter<-iter+1 numer<- -numer } return(this.pi) } What you want is probably a while loop, testing for a level of convergence like this simple method for calculating pi. Jim __ 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] help comparing two median with R
Pedro A Reche wrote: > Dear R users, > I am new to R and I would like to ask your help with the following > topic. I have three sets of numeral data, 2 sets are paired and a > third is independent of the other two. For each of these sets I have > obtained their basic statistics (mean, median, stdv, range ...). > Now I want to compare if these sets differ. I could compare the mean > doing a basic T test . However, I was looking for a test to compare > the medians using R. If that is possible I would love to hear the > specifics. Hi Pedro, You can use the Mann-Whitney test ("wilcox" with two samples), but you would have to check that the second and third moments of the variable distributions were the same, I think. Jim __ 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] indexing a subset dataframe
Mandy Barron wrote: > Hello > I am having problems indexing a subset dataframe, which was created > as: > >>waspsNoGV<-subset(wasps,site!="GV") > > > Fitting a linear model revealed some data points which had high > leverage, so I attempted to redo the regression without these data > points: > >>wasps.lm<-lm(r~Nt,data=waspsNoGV[-c(61,69,142),]) > > which resulted in a "subscript out of bounds" error. > > I'm pretty sure the problem is that the data points identified in the > regression as having high leverage were the row names carried over from > the original dataframe which had 150 rows, but when I try to remove data > point #142 from the subset dataframe this tries to reference by a > numerical index but there are only 130 data points in the subset > dataframe hence the "subscript out of bounds" message. So I guess my > question is how do I reference the data points to drop from the > regression by name? > Hi Mandy, You're correct in that the old indices are no longer valid in the new dataframe. If you want to use the original indices (i.e. you can't just identify the new row indices in the new dataframe), you can do this: waspsNoGV$oldindices<-which(wasps$site != "GV") wasps.lm<-lm(r~Nt, data=waspsNoGV[-(wasps$oldindices %in% c(61,69,142))]) Jim __ 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] Reasons to Use R
(Ted Harding) wrote: > On 12-Apr-07 10:14:21, Jim Lemon wrote: > >>Charilaos Skiadas wrote: >> >>>A new fortune candidate perhaps? >>> >>>On Apr 10, 2007, at 6:27 PM, Greg Snow wrote: >>> >>> >>> >>>>Remember, everything is better than everything else given the >>>>right comparison. >>>> >> >>Only if we remove the grammatical blip that turns it into an infinite >>regress, i.e. >> >>"Remember, anything is better than everything else given the right >>comparison" >> >>Jim > > > Oh dear, I would be disappointed with that, Jim. > > I was rather enjoying the vision of a "topological sort tree" > (ordered by "better according to some comparison") in which every > single thing had everything else hanging off it, and in turn was > hanging off everything else! > Sorry, Ted, I think Benoit Mandelbrot beat you to it. Jim __ [EMAIL PROTECTED] 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] Putting 2 breaks on Y axis
Inman, Brant A. M.D. wrote: > R plotting experts: > > I have a bivariate dataset composed of 300 (x,y) continuous datapoints. > 297 of these points are located within the y range of [0,10], while 2 > are located at 20 and one at 55. No coding errors, real outliers. > > When plotting these data with a scatterplot, I obviously have a problem. > If I plot the full dataset with ylim = c(0,55), then I cannot see the > structure in the data in the [0, 10] range. If I truncate the y axis > with ylim = c(0,10), then I cannot see the 3 outliers. If I break the y > axis from 10 to 20 (using plotrix functions), I still do not see the > data optimally because of the white space from y=20 to y=55. > > What I would like to do is break the y axis at 2 points, roughly 10-20 > and 20-55. Is there a function that can break an axis in 2 places? > Hi Brant, gap.plot in the plotrix package can do one break, and it is possible to do two, as gap.boxplot does. It wouldn't be too difficult to recode gap.plot to get more than one break. I'll see what I can do today. Jim __ [EMAIL PROTECTED] 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] Tweaking my plot of matrix as image
Wee-Jin Goh wrote: > Greetings list, > > I have a rectangular 20 x 20 matrix with values in the range of [0 , > 1]. I'd like to plot it as an image. To that end, I have used the > image() function that seems to do what I want. Now, I just want to > tweak it to look perfect. So here is my question: > > At the moment, the values of the axis range from [0, 1]. I want it to > show the row and column of the matrix. How do I do that? > Perhaps color2D.matplot will suit you. It automatically shows the row and column indices on the plot in the same order as conventional matrix displays. Jim __ [EMAIL PROTECTED] 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] Reasons to Use R
Charilaos Skiadas wrote: > A new fortune candidate perhaps? > > On Apr 10, 2007, at 6:27 PM, Greg Snow wrote: > > >>Remember, everything is better than everything else given the right >>comparison. >> Only if we remove the grammatical blip that turns it into an infinite regress, i.e. "Remember, anything is better than everything else given the right comparison" Jim __ [EMAIL PROTECTED] 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] &500 and above ignored
Constant Depièreux wrote: > Hello, > > I have a data crunching program which causes me a problem. > > Some of the data are identified with an & sign followed by a integer. > No problem is experienced when analysing data below &500, but value > above are ignored. > > Is there some limitation in R on this topic? > Hi Constant, As Ted replied, the question is somewhat mysterious. Are these data from something like MS VBA code, where variable types can be specified with a number of prefixed symbols? If it is just a quirk of the data format and you know that the ampersand is always followed by an integer (or a float or a double...) you could just discard the ampersand when reading the data file. gsub("&","",incoming_data) Fancier substitutions that will not discard ampersands that are needed are left to someone with a head for regular expressions Jim __ 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] bug in plotrix 2.2
Hi all, Sorry to report that there is a minor bug in the floating.pie function in the new version of plotrix. I inadvertantly changed the bouyancy constant and some users may find that they are farther down the ordinate than they should be. This will be fixed in version 2.2-1. Jim __ 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] substitute NA values
Sergio Della Franca wrote: > Dear R-Helpers, > > > I have the following data set(y): > > Test_Result #_Test > t 10 > f 14 > f 25 > f NA > f 40 > t45 > t44 > 47 > tNA > > > I want to replace the NA values with the following method: > - for the numeric variable, replace NA with median > - for character variable , replace NA with the most frequent level > > If i use x<-na.roughfix(y) the NA values are correctly replaced. > But if i x<-na.roughfix(y$Test_Result) i obtain the following error: > > roughfix can only deal with numeric data. > > How can i solve this proble that i met every time i want to replace only the > NA values of a column (type character)? > Hi Sergio, In the prettyR package is the Mode function. This returns the mode of a vector as a character string. So I think this would do what you want: library(prettyR) testvec<-c(sample(LETTERS[1:4],20,TRUE),NA,NA) testvec[is.na(testvec)]<-Mode(testvec) You could do the same trick with the median function for the numeric values. Jim __ 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] Truncated x-axis values
"Urban, Alexander" <[EMAIL PROTECTED]> wrote: > Hello > >I'm new to this group. I looked up the last two > >hour in the help file > > and in the archives of this group, but didn't > >find anything. > >I hope my question is not too dump: >I'm printing a graph with vertical labels on the > >x-axis (necessary due > >to many labels). Unfortunately the png truncates > >the labels halfway > >through, so that you can only read the last 7 > >digits of the label. > >Snice I'm already asking :-): Is there a > >possibility to tell R: If > >there are so many labels that you write them on > >top of each other, > >take only e.g. every 2nd... > There sure is, Alex. Have a look at staxlab in the plotrix package. Jim __ 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] Colored boxes with values in the box
Pappu, Kartik wrote: > Hi all, > > I have a x, y matrix of numbers (usually ranging from 0 to 40). I need > to group these numbers and assign a color to each group (for example 0 > to 15 - Blue, 16-30- Yellow, and 31-40- Red). Then I need to draw a > rectangular matrix which contains X x Y boxes and each box has the > corresponding value from the input matrix and is also colored according > to which group (i.e red, yellow, or blue) that value falls into. > > I have used the color2D.matplot function from the plotrix package, but > I cant quite figure out how to group the values to represent red blue > and yellow colors. > Hi Kartik, color2D.matplot isn't designed for this, but with a few tricks, I think you can get what you want. Try this: xmat<-matrix(sample(0:40,100,TRUE),nrow=10) # trick 1 - calculate values that give you the colors for ranges color2D.matplot(floor(xmat/15+1),c(1,1,0),c(0,1,0),c(0,0,1)) # trick 2 - Use boxed.labels rather than the inbuild value display boxed.labels(sort(rep(9.5:0.5,10)),rep(seq(9.5,0.5,by=-1),10),xmat) # trick 3 - Use color.legend to show the group colors color.legend(0,-2,3,-1.3,1:3,c("red","yellow","blue")) You will have to wait until plotrix v2.2 is on CRAN as I am just submitting it, and the color.legend function, requested only a few weeks ago, is new to that version. Jim __ 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] Ticks on barplots
Michael H. Prager wrote: > Dear Gurus, > > Using R 2.4.1 on Windows XP > > I am generating stacked barplots of age-composition of fish populations > (Y) over time (X). As there are many years, not every bars is labeled. > When looking at the plot, it becomes difficult to associate labels with > their bars. > > We have improved this a bit by using axis() to add a tickmark below each > bar. Can anyone suggest a way to draw ticks ONLY at bars where a tick > label is drawn? Or to make such ticks longer than those where there is > no label? > > This is going into a function, so I'm hoping for a method that doesn't > require looking at the plot first. > > I have attached a PDF. > > # sample code (simplified) # > mp <- barplot(t(N.age), xlab = "Year", axisnames = FALSE) > axis(side = 1, at = mp, labels = rownames(N.age), tcl = -0.75) > Hi Mike, PDF didn't get through, but I think I understand what you want. Here's a suggestion: oddaxlab<-function(side=1,at,labels) { at<-at[which(nchar(labels)>0)] labels<-labels[which(nchar(labels)>0)] axis(side,at,labels) } groupie<-matrix(rnorm(32)+3,nrow=8) labels<-matrix(c(c("1","","","","5","","7",""), c("","","","","13","","",""), c("17","","","20","","","",""), c("25","","","","","","31","")),nrow=8) bpos<-barplot(groupie,beside=TRUE) oddaxlab(at=barpos,labels=labels) What the function does is only draw ticks and labels where there is a non-empty label. You pass only those labels that you want to appear. Hope I have gotten the right idea. Jim __ 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] Off topic:Spam on R-help increase?
Horacio Castellini wrote: > Ya me parecía que no me pasaba solo a mi... :) uhmmm falló el spam-filter? > Si, es todos que lee R-news, pero maravillo, que es el palabra para "spam" en español? Jim __ 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] reading a text file with a stray carriage return
jim holtman wrote: > How do you define a carriage return in the middle of a line if a carriage > return is also used to delimit a line? One of the things you can do is to > use 'count.fields' to determine the number of fields in each line. For > those lines that are not the right length, you could combine them together > with a 'paste' command when you write them out. > > On 3/7/07, Walter R. Paczkowski <[EMAIL PROTECTED]> wrote: > >> >> Hi, >> I'm hoping someone has a suggestion for handling a simple problem. A >> client gave me a comma separated value file (call it x.csv) that has >> an id and name and address for about 25,000 people (25,000 records). >> I used read.table to read it, but then discovered that there are stray >> carriage returns on several records. This plays havoc with read.table >> since it starts a new input line when it sees the carriage return. In >> short, the read is all wrong. >> I thought I could write a simple function to parse a line and write it >> back out, character by character. If a carriage return is found, it >> would simply be ignored on the writing back out part. But how do I >> identify a carriage return? What is the code or symbol? Is there any >> easier way to rid the file of carriage returns in the middle of the >> input lines? >> Any help is appreciated. >> Walt Paczkowski >> Probably using Windows with a CR/LF newline. You can have carriage returns (Ctrl-M - ASCII 13) or line feeds (Ctrl-L - ASCII 10) embedded in lines. You can probably just write a function in C or something that reads characters, checks that it and the last character is not a CR/LF pair and throws out the second character if it is CR or LF or any other troublesome byte. (I once had to trace null characters that were embedded in files - they didn't show up on the display, but clobbered the file reads). Jim __ 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] Identifying points in a plot that have duplicate values
David Lloyd wrote: > I have code like this: - > > #--- > -- > > x=scan() > 0 0 0 0 0 1 2 3 4 > > y=scan() > 1 1 1 2 2 1 3 4 5 > > plot(x,y) > > identify(0,1,3) #Allows me to select manually to identify co-ordinate > (0,1) as being duplicated 3 times > identify(0,2,2) #Allows me to select manually to identify co-ordinate > (0,2) as being duplicated 2 times > #--- > -- > > Is there not a way I can automatically display if points are duplicated > and by how many times? > > I thought if I 'jittered' the points ever so slightly I could get an > idea of how many duplicates there are but with >100 points the graph > looks very messy. > Hi David. In the plotrix package there are a few functions that might be helpful. cluster.overplot - moves ovelying points into a small cluster up to 9 count.overplot - displays the number of overlying points sizeplot - displays symbols with size relative to the number of points Jim __ 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] barplot2, gap.barplot
Marc A. Rohling wrote: > Hello, > > I try to handle a simple bar-plot, but it turns out to be not as simple > as I thought. ... > As you can see, because of the 4th bar (value > 45), the other bars look > a little bit tiny: there is too much white-space. What I need to handle > this problem is a function to insert a gap. > > I tried to use gap.barplot, but unfortunately, it cannot handle any of > the parameters I need from the barplot2-function. > > After days of missing effort, I am sick of this problem. Is there a > solution? Hi Marc1, As Marc2 said, the use of discontinuous axes in plots is a contentious one. No, I did not try to make gap.barplot compatible with barplot2 as the two seem to have different aims. gap.barplot is one solution to the troublesome issue of the outlier. What I would suggest as a one-off solution (to the horror of some) is to subtract, say, 25 from the outlier value, do the barplot, then: par(xpd=TRUE) axis.break(2,21,style="gap") text(barpos[4],24,48.6) I realize that your plot is more complex (I don't have gplots, etc. installed so I can't reproduce it at the moment), but that might give you something with which to work. Jim __ 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] something missing in summary()
Gerard Smits wrote: > > just noticed that two key pieces of information are not given by > the summary() command: N and SD. we are given the N missing, but > not the converse. I know these summary value can be obtained easy, > but can't understand why these two pieces of information are not > provided with the other info. > This was one reason that I wrote the describe function in the prettyR package. You can roll your own summary, and describe makes a reasonable attempt to sort out the common data types. Jim __ 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] symbols hidden in polar.plot
Sumitrajit Dhar wrote: > Hi Folks, > > Here is my attempt at a simple polar plot. > > > > pos <- seq(0,360,by=5) > > tspk <- rep(c(1,0,1),c(13,47,13)) > > require(plotrix) > > polar.plot(tspk,pos,rp.type="s",point.symbols=17,point.col="green4") > > > I only see half the symbols, the other half of each symbol is hidden > under the circular grid. In fact if I change rp.type="r", I see the > lines being plotted and then the grid gets plotted over it and hides > the lines. > > What am I doing wrong? Hi Sumitrajit, You aren't doing anything wrong, just unusual. 47 of your symbols are placed exactly in the center of the plot, so that only one of them is visible. Most of that is covered by the radial lines that the function draws. The other 26 are placed on the periphery of the plotting area and seven of these will have the same radial lines drawn across them. If you want to see what I mean, try this: fix(radial.plot) now comment out line 78 # segments(0,0,xpos,ypos,col=grid.col) save and quit your editor. Now try your last line like this: polar.plot(tspk,pos,rp.type="s",point.symbols=17, point.col="green4",show.grid=FALSE) This gives me a chance to ask any interested R users the question: "Do you prefer the radial.plot family to draw the lines, symbols or polygons first or last (that is, on top of everything else)?" Thanks for any answers. Jim __ 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] heatmap color specification
Xiaohui wrote: >... > Then, I did a heatmap for 'test' matrix. But for now, I want to specify > each of the cell in the heatmap according to the values of the > corresponding matrix elements of test. > > Let's say: col<-c("red","yellow","green") > > for test[1,1], the color on the map should be "red". > > I have tried par('usr') and par('mar') with rect function. But this does > not work because the rect shift from the original map. Could any one > tell me how to fill the cells on the map with corresponding values? Or > can we get the actual coordinates of the image excluding the dendregram. > Hi Xiaohui, You may be looking for something like color2D.matplot in the plotrix package or "image" in the graphics package. Jim __ 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] R in Industry
Ben Fairbank wrote: > To those following this thRead: > > There was a thread on this topic a year or so ago on this list, in which > contributors mentioned reasons that corporate powers-that-be were > reluctant to commit to R as a corporate statistical platform. (My > favorite was "There is no one to sue if something goes wrong.") > > One reason that I do not think was discussed then, nor have I seen > discussed since, is the issue of the continuity of support. If one > person has contributed disproportionately heavily to the development and > maintenance of a package, and then retires or follows other interests, > and the package needs maintenance (perhaps as a consequence of new > operating systems or a new version of R), is there any assurance that it > will be available? With a commercial package such as, say, SPSS, the > corporate memory and continuance makes such continued maintenance > likely, but is there such a commitment with R packages? If my company > came to depend heavily on a fairly obscure R package (as we are > contemplating doing), what guarantee is there that it will be available > next month/year/decade? I know of none, nor would I expect one. > > As R says when it starts up, "R is free software and comes with > ABSOLUTELY NO WARRANTY." > Hi Ben, This is a good point, and one that has been made many times. One aspect of the "price" of R is that it is user-determined. If you want to take the time to check that your particular analysis is doing what you think it's doing, that costs you something. For the user who just wants to push the button and pass the buck to the software company if anything goes wrong, R is not ideal. If you want to go beyond just using R, you can report problems, share your knowledge with others, and maybe contribute a bit here and there to the project. Perhaps even decide to take over maintaining an obscure package if it is of sufficient value to you. All this costs you something. It may pay you back, for the knowledge you gain from being involved in a cooperative project is worth something, too. While I have tried to contribute what I can, I think that what I have gained from R is much more than I have given. However, if the great majority of R users feel that way, it is a pretty good example of overall benefit from cooperation. You don't pay any money, but you do take your chances. Jim __ 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] setting a number of values to NA over a data.frame.
John Kane wrote: > This is probably a simple problem but I don't see a > solution. > > I have a data.frame with a number of columns where I > would like 0 <- NA > Hi John, You might have a look at "toNA" in the prettyR package. Wait for version 1.0-4, just uploaded, as I have fixed a bug in that function. Jim __ 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] R in Industry
Matthew Keller wrote: > Far from flaming you, I think you made a good point - one that I > imagine most people who use R have come across. The name "R" is a big > impediment to effective online searches. As a check, I entered "R > software", "SAS software", SPSS software", and "S+ software" into > google. The R 'hit rate' was only ten out of the first 20 results (I > didn't look any further). For the other three software packages, the > hit rates were all 100% (20/20). > > I do wonder if anything can/should be done about this. I generally > search using the term "CRAN" but of course, that omits lots of stuff > relevant to R. Any ideas about how to do effective online searches for > "R" related materials? > Try "r stats". I get 18/20 on Google with that. Jim __ 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] Adding Scale to image
Peter Robinson wrote: > Dear List, > > I have used the image() function to show a heat plot of a matrix of data > whose intensity is color-coded. I have two questions that I have not > been able to solve by using the help system or google. > > 1) How can one add a scale/legend that shows what numerical values a > given color corresponds to? You can use the gradient.rect function in the plotrix package to display a rectangular bar with a specified number of color "slices" in it. For an example of how to make this into a color legend, see the color2D.matplot function in the same package. If this is of interest to R users, I could include a color.legend function in plotrix that would do it all. Jim __ 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] countour and poygon shading
J.M. Breiwick wrote: > Hi, > > I have a contour plot and I want to shade a polygon (the area below a line) > but the polygon shading wipes out the contour lines. Does anybody know how > to shade the polygon and still see the contour lines? Thanks. > Hi Jeff, If you're talking about polygon.shadow in the plotrix package, you have to call that function before you draw the overlying figure and anything else that would lie within the shadow. Jim __ 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] parallel coordinates plot
Marco Helbich wrote: > Dear List, > > I want to make a parallel coordinates plot with the specific variables on > the abscissa and the cases on the ordinate should be dyed dependent on > another nominal variable from the data frame. I use the parcoord function. > Hi Marco, If I understand your question, you want to color the points displayed for each variable dependent upon some nominal value (probably a factor). Say you have a data frame like this, you could plot: my.df<-data.frame(var.names=paste("V",1:10,sep=""), var.values=rnorm(10)+5,var.colors=sample(2:4,10,TRUE)) plot(my.df$var.values,col=my.df$var.colors,axes=FALSE) box() axis(1,at=1:10,labels=as.character(my.df$var.names)) axis(2) Jim __ 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] quilt.plot
Dunja Drvar wrote: > Dear all, > I have a problem with plotting. > I have an irregular set of data, where latitude is listed from bigger to > smaller values. So, I cannot plot with image.plot. > On the other hand, quilt.plot solves the problem, but it can't take the > definition of color. It gives the feedback: > > Error in image.plot(out.p, col = tim.colors(64), ...) : > formal argument "col" matched by multiple actual arguments > > The question is: is there a way to define the color palette in quilt.plot? Hi Dunja, I think the problem is due to the position of the ... argument. In image.plot it is first, meaning that all other arguments have to be named. Thus when you pass col= as part of ... in quilt.plot, it is placed in the initial ... in the call to image.plot, generating two col= arguments. I think the quickest hack is to insert an explicit col= argument into the code for quilt.plot and add it into the call to image.plot within the function as below. function (x, y, z, nrow = 64, ncol = 64, grid = NULL, add.legend = TRUE, col=tim.colors(64), ...) { x <- as.matrix(x) if (ncol(x) == 2) { z <- y } if (ncol(x) == 1) { x <- cbind(x, y) } if (ncol(x) == 3) { z <- x[, 3] x <- x[, 1:2] } out.p <- as.image(z, x = x, nrow = nrow, ncol = ncol, na.rm = TRUE) if (add.legend) { image.plot(out.p, col = col, ...) } else { image(out.p, col = col, ...) } } The modified example: quilt.plot(ozone2$lon.lat, ozone2$y[16, ], add.legend = FALSE,col=rainbow(64)) works for me. Jim __ 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] color of opposite sign values in filled.contour
Claudia Tebaldi wrote: > Dear R-helpers, > > I'm plotting geophysical data in the form of contours using > "filled.contour". The display would be much more effective if the areas > with negative values could be color coded > by -- say -- "cold colors" in the range of blue to green, and conversely > the areas with positive values got plotted with "warm colors", from yellow > to red. > Right now if I use a palette spanning the spectrum I need the entire range > is associated with the actual range of the data, which can be positively > or negatively skewed, and as a result the position of the zero is totally > arbitrary. > I'm wondering if someone out there has come up with a clever way to set > the color scale accordingly, as a function of the actual range of the > values in the matrix that is being plotted. Ideally, it would be neat to > still use the entire spectrum, but sampling differently the cold and warm > subsets accordingly to the extent of the negative and positive values in > the data. > > Also, when I try to play around in an ad hoc fashion with the palette I > often get funny results in the legend, with color-scale wrapping or blank > cells at one of the extremes. I cannot hack effectively the code of the > filled.contour function, obviously... > > Hi Claudia, Have a look at color.scale in the plotrix package. You can specify quite a variety of different color ranges into which your numeric values will be transformed. If you want different color ranges for positive and negative values, you can calculate them separately. Here's an example using blue to green for negative values and yellow to red for positive: testval<-c(-3,6,-1,8,0,-2,4,10,12) testcol<-rep(0,length(testval)) testcol[testval<0]<-color.scale(testval[testval<0],0,c(0,1),c(1,0)) testcol[testval>=0]<-color.scale(testval[testval>=0],1,c(1,0),0) plot(testval,col=testcol,pch=19) You might also be interested in color.scale.lines Jim __ 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] setting new working directories
Bill Shipley wrote: > Hello, and Happy New Year. My default working directory is getting very > cluttered. I know that I should be using a different working directory for > each project (I work in Windows), but do not know how to go about creating > different ones and moving back and forth between them. I have read Venables > & Ripley (Modern Applied Statistics with S-PLUS, 1994) but this seems out of > date with respect to this topic and have searched through the documentation > but cannot find a clear explanation for doing this. Can someone point me to > the proper documentation for creating and using different working > directories from within Windows (please, no comments about switching to > UNIX...). > Thanks. > I'm not sure to which New Year you refer, but thanks and the same to you. I think you may want to automatically start up R in a directory for each project. There is a discussion of that in Kickstarting R at: http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_start.html Basically, you can create icons on the desktop that will start R in a number of directories. In Windows, don't worry about adding the line to your "R" startup file, just set the "Start Program in" to the desired directory in the Properties dialog of the shortcut. You can also set up an R file that gives you an interactive choice when the program starts. Create a file like this: cat("R programming\n") cat("Animals\n") cat("Vegetables\n") cat("Minerals\n") cat("Type in the first letter of the project -") answer<-toupper(strsplit(readline(""))[1]) if(answer == "R") setwd("c:/jim/R/programs") if(answer == "A") setwd("c:/jim/things/animals") ... and say you name it c:\jim\R\SelectProject.R (notice that Windows uses backslashes but you use slashes in R) put the following line in your .First function: source("c:/jim/R/SelectProject.R") and you should be able to select your project and directory on startup. Jim __ 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] Genotype importing from Sequenom
Farrel Buchinsky wrote: > Sequenom has an odd format of calling a SNP genotype > > gg > [1] "C" "GA" "A" "C" "C" "AG" "C" "C" "T" "G" > > homozygous A is called A and heterozygous is called AT > The genetics package cannot handle the fact that some genotypes are declared > with 2 letter while other are declared with only 1. Consequently the > genotype() or makeGenotypes() will not work. > > I need to either find a clever way that the genetics package actually does > do this. I think it may reside in the "method" argument but do not know how > to manipulat it. Alternatively I have to come up with some nifty string > manipulation. Any ideas? > gg1char<-nchar(gg)==1 gg[gg1char]<-paste(gg[gg1char],gg[gg1char],sep="") Jim __ 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] counties in different colours using map()
Tord Snäll wrote: > Hi, > I would like to plot a map of US counties using different colors. map() > seems to be the function to use, e.g. > library(maps); map('usa'); map('county', 'colorado', add=T,fill = T, > col=c(1:5)) > plots Colorado counties using colours 1 to 5. > > However, I want each color to represent a certain value - a value to be > picked from a data frame. > This code should show a correspoding map at the level of states: > state.names <- system('tr "[A-Z]" "[a-z]"', state.name) > map.states <- unix('sed "s/:.*//"', map(names=T,plot=F)) > state.to.map <- match(map.states, state.names) > color<- votes.repub[state.to.map, votes.year = 1900] / 100 > map('state', fill=T, col=color); map('state', add=T) > Hi Tord, I don't know if this matches the color to the state as I couldn't get your "unix" function to work, but it does what I think you want. library(maps) map("usa") data(votes.repub) library(plotrix) state.col<-color.scale(votes.repub[,30],c(0,1),0,c(1,0)) map("state",fill=TRUE,col=state.col) Jim __ 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] Problem to generate training data set and test data set
Aimin Yan wrote: > I have a full data set like this: > > aa basaas bms ams bcuacu omega y > 1 ALA 0 127.71 0 69.99 0 -0.2498560 79.91470 outward > 2 PRO 0 68.55 0 55.44 0 -0.0949008 76.60380 outward > 3 ALA 0 52.72 0 47.82 0 -0.0396550 52.19970 outward > 4 PHE 0 22.62 0 31.21 0 0.1270330 169.52500 inward > 5 SER 0 71.32 0 52.84 0 -0.1312380 7.47528 outward > 6 VAL 0 12.92 0 22.40 0 0.1728390 149.09400 inward > .. > > > aa have 19 levels, and there are different number of observation for each > levels. > I want to pick 75% of observations of each levels randomly to generate a > training set, > and 25% of observation of each levels to generate a testing set. > Hi Aimin, I haven't tested this exhaustively, but I think it does what you want. get.prob.sample<-function(x,prob=0.5) { xlevels<-levels(as.factor(x)) xlength<-length(x) xsamp<-rep(FALSE,xlength) for(i in xlevels) { lengthi<-length(x[x == i]) xsamp[sample(which(x == i),lengthi*prob)]<-TRUE } return(xsamp) } get.prob.sample(mydata$aa,0.75) Jim __ 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] OT: any recommendation for scripting language
Wensui Liu wrote: > Right now, I am using SAS and S+/R. As a new year resolution, I am > planning to learn a scripting language. > > from statisticians' point of view, which scripting language is worth > to learn, perl, python, or any other recommendation? (Most likely, I > will be learning it in windows.) Since I am not in research, I will > prefer one widely used in industry and related to statistical work. > > if you recommend one, I will really appreciate it if you could point > out a good source for learning as well. > Hi Wensui, I use Tcl-Tk quite a bit. I found it very easy to learn, and as you can see from the tcl-tk package in R, very flexible. It is particularly good at spanning the range from a slick-looking GUI to low level file and computation operations. I'm currently using it to pick individual records out of a database, calculate age and sex specific deviations from population norms and then present a graphical display to the user. There is not only excellent documentation available for Tcl-Tk, but several newsgroups and wikis. http://www.tcl.tk Jim __ 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] cohen kappa for two-way table
Dylan Beaudette wrote: > Greetings, > > I am a bit confused by the results returned by the functions: > cohen.kappa {concord} > classAgreement {e1071} > > when using a two-way table. > > > for example, if I have an matrix A, and a similar matrix B (same > dimensions), then: > > matrix A and B can be found: > http://casoilresource.lawr.ucdavis.edu/drupal/files/a_40.txt > http://casoilresource.lawr.ucdavis.edu/drupal/files/b_40.txt > > A <- matrix(unlist( read.table('a_40.txt'), use.names=FALSE), ncol=14) > B <- matrix(unlist( read.table('b_40.txt'), use.names=FALSE), ncol=14) > If I interpret this correctly, you are considering the numbers in A and B to be nominal variables representing levels of some data attribute. What cohen.kappa wants is: 1(type=counts) a matrix of counts where each cell represents the number of methods (rows are different methods) that classified the data objects into levels (columns are different levels). 2(type=scores) a matrix of scores where each cell represents the level assigned by a method (rows again) to a data object (columns are data objects here). If your numbers are counts, you can get a sensible kappa for _each_ matrix. If your numbers are scores, you can get a sensible kappa by specifying type=scores for _each_ matrix As far as I can see, you are computing a sparsely populated table of the two matrices and passing that, and I don't see how that can give a meaningful result. I suspect that the numbers might be counts in the first place, but they are being used as scores. > Secondly, when using the classAgreements() function I get different numbers: > I'll let someone who knows more about the classAgreement function deal with this. Jim __ 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] Show date on graph
Syed Abid Hussaini wrote: > I have a character "2006-11-06" which was originally scanned from a csv file. > This character is > named date. I now use mtext (date) on a plot and i see strange cluttered > characters instead of > 2006-11-06. I tried many ways but i dont know whats going on. Then for > testing i made an > artificial character d <- ("2006-11-06") and now when i do mtext (d) it shows > up on the plot. > While both date and d return "2006-11-06" only d shows up on the plots. Any > help would be appreciated. > > > Hi Syed, If you try to display something with mtext, it expects the object to be a character string. When you just print the object, the print method works out that it is a date object and silently converts it to a character string to be printed. Try this: mtext(format(date,"%Y-%m-%d"),...) Also note that it isn't a great idea to use "date" to name a variable. Even though you can now get away with it, using the same name for two things (a function and a variable) often comes back to haunt one. Jim __ 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] axis in an image() plot
Ricardo Rodríguez - Your XEN ICT Team wrote: > Hi all, > > I've found quite usefull colored-grid created by image() but I'm facing a > doubt I am not able to solve. > > Given the following data rectangle... > > 1 2 3 4 5 6 7 8 9 10 11 12 13 14 > 1 12 22 0 7 2 1 0 2 0 2 6 -3 0 3 > 2 0 -1 0 9 3 -4 0 0 0 0 3 0 0 0 > 3 29 45 6 12 16 85 -2 0 -3 -4 89 -1 -1 1 > 4 2 9 3 6 17 3 -2 -9 -2 8 -1 0 0 0 > 5 44 16 -3 21 23 3 2 1 0 -2 13 18 -5 2 > > I am not able to draw x and y axis labeled 1 to 14 and 1 to 5 by 1. I've > tried a number of options by using axis() to no avail. > > It will be also very helpfull to be able to draw the value of each x,y > combination within its position in the grid. Text() seems to be the answer, > but I am not able yet to get the correct position for each label. > > Please, could you point me in the right direction or offer some example? > Hi Ricardo, This might be what you want (say your data frame is called my.df): library(plotrix) color2D.matplot(my.df,c(1,0),c(0,0),c(0,1)) text(rep(0.5:13.5,5),rep(seq(4.5,0.5,by=-1),14), unlist(my.df),col="white") and in fact it looks so neat that I might add it as an option. Jim __ 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] Plot with two seperate y axis
Thorsten Muehge wrote: > Hello, > I would like to plot the following matrix: > Wk=x achsis. > Para 1 = left y-axis as a barplot > para 2 right y-axis as a normal scatter plat. > > I could not find such a solution in any of my documentation. > > Can someone help me? > > Thanks a lot > Thorsten > > WkPara 1 Para 2 > 312000 99.8 > 322005 99.0 > 332002 98.0 > 341090 98.5 > 352001 99.1 > 362010 97.0 > 372010 98.8 > Hi Thorsten, Is this what you mean? par(mar=c(5,4,4,4)) xpos<-barplot(mueghe.df$Para.1) axis(1,at=xpos,labels=mueghe.df$Wk) par(new=TRUE) plot(xpos,mueghe.df$Para.2,xlim=par("usr")[1:2],xaxs="i", ylim=c(0,100),type="n",xlab="",ylab="",axes=FALSE) axis(4) points(xpos,mueghe.df$Para.2) Jim __ 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.