Re: [R] mtext, picking subscript text from colnames(df)
Works excellent. Thanks! Tord Henrique Dallazuanna wrote: Try: mtext(eval(parse(tex=paste(expression(mu[, colnames(PresEsts)[2],]), sep=))),side=2,at=max(y)-15,las=1) -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Tord Snäll Department of Ecology Swedish University of Agricultural Sciences (SLU) P.O. 7002, SE-750 07 Uppsala, Sweden Office/Mobile/Fax +46-18-672612/+46-730-891356/+46-18-673537 E-mail: [EMAIL PROTECTED] www.nvb.slu.se/staff_tordsnall __ 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] mtext, picking subscript text from colnames(df)
Hi! Could someone give advise on how to plot Greek letters where subscript text is picked from the names of a data.frame. I want what appears using this code mtext(expression(mu[Mountain]),side=2,at=max(y)-7,las=1,cex=1.5) but I would like to do it using something like this: mtext(expression(mu[colnames(PresEsts)[2]]),side=2,at=max(y)-15,las=1) BTW, colnames(PresEsts)[2] [1] Mountain Thanks! /Tord -- Tord Snäll Department of Ecology Swedish University of Agricultural Sciences (SLU) P.O. 7002, SE-750 07 Uppsala, Sweden Office/Mobile/Fax +46-18-672612/+46-730-891356/+46-18-673537 E-mail: [EMAIL PROTECTED] www.nvb.slu.se/staff_tordsnall __ 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] order of values in vector
Dear all, I would like to get the order of the values in a vector. I have tried rank(), order() and searched the archive, though without success. Here is an example of a try x= c(20,30,50,40,60,10) cbind(sort.list(x),x) x [1,] 6 20 [2,] 1 30 [3,] 2 50 [4,] 4 40 [5,] 3 60 [6,] 5 10 but I was hoping to get this: x [1,] 2 20 [2,] 3 30 [3,] 5 50 [4,] 4 40 [5,] 6 60 [6,] 1 10 I'm most grateful for a tip! cheers, Tord -- Tord Snäll Department of Ecology Swedish University of Agricultural Sciences (SLU) P.O. 7002, SE-750 07 Uppsala, Sweden Office/Mobile/Fax +46-18-672612/+46-730-891356/+46-18-673537 E-mail: [EMAIL PROTECTED] www.nvb.slu.se/staff_tordsnall __ 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] map data.frame() data after having linked them to a read.shape() object
Dear all, I try to first link data in a data.frame() to a (polygon) read.shape() object and then to plot a polygon map showing the data in the data.frame. The first linking is called link in ArcView and relate in ArcMap. I use the code shown below, though without success. Help with this would be greatly appreciated. Thanks! Tord require(maptools) # Read shape file (one row per county) a=read.shape(myshp.shp, dbf.data=TRUE, verbose=TRUE) str(a) ..- attr(*, maxbb)= num [1:4] -100 4900 ..- attr(*, class)= chr ShapeList $ att.data:'data.frame': 490 obs. of 60 variables: ..$ STATE_FIPS: Factor w/ 12 levels 04,06,08,..: 11 11 11 11 4 5 5 5 5 5 ... [snip] ..$ STACOUNT4 : Factor w/ 489 levels ArizonaApache,..: 437 460 451 453 147 207 195 198 231 206 ... ..- attr(*, data_types)= chr [1:60] C C C C ... - attr(*, class)= chr Map # Read case data (one row per case) cases = read.table(cases.txt, h=T,) str(cases) 'data.frame': 431 obs. of 8 variables: $ Year: int 1950 1950 1950 1951 1956 1957 1959 1959 1959 1959 ... $ Case: int 3 1 2 1 1 1 2 4 1 3 ... $ stacount: Factor w/ 106 levels ArizonaApache,..: 1 66 76 66 26 29 15 25 30 60 ... # table the cases data PER Year, PER County (County = stacount) temp = t(table(cases[,c(Year,stacount)])) stacount = dimnames(temp)$stacount temp = cbind(stacount, as.data.frame(temp[,1:ncol(temp)],row.names=F)) str(temp) 'data.frame': 106 obs. of 50 variables: $ stacount: Factor w/ 106 levels ArizonaApache,..: 1 2 3 4 5 6 7 8 9 10 ... $ 1950: int 1 0 0 0 0 0 0 0 0 0 ... [snip] $ 2005: int 0 0 0 0 0 0 0 0 0 0 ... # Pick out a temporary attribute data.frame datfr = a$att.data # Merge the temporaty data frame with tabled cases for(i in 2:ncol(temp)){ datfr = merge(datfr, temp[,c(1,i)], by.x=STACOUNT4, by.y=stacount, all.x=T, all.y=F) } #Replace NAs with 0: for(i in 61:109){ datfr[,i] = ifelse(is.na(datfr[,i])==T,0,datfr[,i]) } str(a$att.data) 'data.frame': 490 obs. of 60 variables: $ NAME : Factor w/ 416 levels Ada,Adams,..: 120 352 265 277 33 210 122 135 372 209 ... [snip] $ STACOUNT4 : Factor w/ 489 levels ArizonaApache,..: 437 460 451 453 147 207 195 198 231 206 ... - attr(*, data_types)= chr C C C C ... # Note that the above data is of attribute type str(datfr) 'data.frame': 490 obs. of 109 variables: $ STACOUNT4 : Factor w/ 489 levels ArizonaApache,..: 1 2 3 4 5 6 7 8 9 10 ... [snip] $ 1951 : num 0 0 0 0 0 0 0 0 0 0 ... [snip] $ 2005 : num 0 0 0 0 0 0 0 0 0 0 ... # Note that at the end of this, data type is not described - it is a simple data frame # bind data together: #Alternative 1: a$att.data = cbind(a$att.data, datfr[,61:109]) # Other alternatives: test = matrix(ncol=49) a$att.data[,61:109] = test a$att.data[,61:109] = datfr[,61:109] # plot: plot(a, auxvar=a$att.data[,61], xlim=c(-125,-99),ylim=c(28,52), xlab=, ylab=, frame.plot=F,axes=F) There were 50 or more warnings (use warnings() to see the first 50) warnings() 49: axes is not a graphical parameter in: polygon(xy$x, xy$y, col,border, lty, ...) 50: frame.plot is not a graphical parameter in: polygon(xy$x, xy$y,col, border, lty, ...) # The a$att.data type has changed to becoming a typical data.frame - attr is not mentioned: str(a$att.data) [snip] $ 2003 : num 0 0 0 0 0 0 0 0 0 0 ... $ 2004 : num 0 0 0 0 0 0 0 0 0 0 ... $ 2005 : num 0 0 0 0 0 0 0 0 0 0 ... -- Tord Snäll Department of Conservation Biology Swedish University of Agricultural Sciences (SLU) P.O. 7002, SE-750 07 Uppsala, Sweden Office/Mobile/Fax +46-18-672612/+46-730-891356/+46-18-673537 E-mail: [EMAIL PROTECTED] www.nvb.slu.se/staff_tordsnall __ 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] counties in different colours using map()
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) It is copied from page 6 in Richard A. Becker, and Allan R. Wilks, Maps in S, ATT Bell Laboratories Statistics Research Report [93.2], 1993. http://public.research.att.com/areas/stat/doc/93.2.ps I also wonder whether the county names are available in the database used by map(), and, if yes, how to extract or utilize them. Thanks! Tord -- Tord Snäll Department of Conservation Biology Swedish University of Agricultural Sciences (SLU) P.O. 7002, SE-750 07 Uppsala, Sweden Office/Mobile/Fax +46-18-672612/+46-730-891356/+46-18-673537 E-mail: [EMAIL PROTECTED] www.nvb.slu.se/staff_tordsnall __ 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] calculate area of outer polygon
Dear all, Does anyone know of a function that calculates the area of the outer polygon constructed from a data frame with co-ordinates? For example, library(splancs) test = rbind(c(0,0), c(10,0),c(10,10),c(0,20)) plot(test) areapl(test) [1] 150 This is OK, but I want the same area to be returned (150) when adding yet another co-ordinate in the middle of the polygon: test = rbind(c(0,0), c(10,0),c(10,10),c(0,20),c(5,5)) plot(test) areapl(test) [1] 100 I have also tested area.owin() in library(spatstat) but the co-ordinates of the outer polygon is one of the arguments. Thanks! Tord -- NOTE, new e-mail and contact information: Tord Snäll Department of Conservation Biology Swedish University of Agricultural Sciences (SLU) P.O. 7002, SE-750 07 Uppsala, Sweden Office/Mobile/Fax +46-18-672740/+46-730-891356/+46-18-673537 E-mail: [EMAIL PROTECTED] www.nvb.slu.se/staff_tordsnall __ 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] plot greek letter in italic
Hi, Could someone please let me know how to plot greek letters in italic. text(0,14,expression(italic(rho)[italic(f)])) only plots the f in italic and text(37,40,expression(italic(rho))) doesn't plot rho in italic. I have checked demo(plotmath), ?plotmath, FAQ, and the archives 2004-2006 without finding the answer. I'm using R 2.1.1. and Windows XP. Thanks! Tord -- Tord Snäll (postdoc) Dept. of Ecology Evolutionary Biology N228 Ramaley, University of Colorado 334 UCB, Boulder, CO, 80309-0334 Phone: +1 720 771 1849 http://spot.colorado.edu/~sharonc/CollingeLab.htm __ 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
Re: [R] code efficiency, extr. info from list
Dear Anders and Paulo, Thanks very much for your recommendations! I did it this way: test2 - unlist(lapply(test, function(x) cbind(x$par[1], x$par[2], x$value, x$conv))) m- as.data.frame(matrix(test2, nrow = dim(grid)[1], ncol = 4, byrow = T)) names(m) - c(s2, rho, value, conv) but I sure there are better ways Sincerely, Tord __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help