haotu : an open lab notebook

2014/08/25

plot rho correlation in R

Filed under: R, R graphics, R Stats — S @ 13:28
cr<-round(cor(a.ran)[2,1],3)
text(.2,-.4,bquote(rho == .(cr)),cex=2)
Advertisements

Order Boxplot in R

Filed under: R, R graphics, R Stats — S @ 11:58
boxplot() 

I have found that this plotting function orders boxes in alphabetical order, at times, so if I want a particular order that the R god is not giving me, then I find it easiest to rename my categories in an alphabetical order in which I want plotted and then us the names argument to relabel the x-axis.  
 

 

2014/08/17

add row to data frame when there are factors

Filed under: Manipulate Data in R, R, R Stats — Tags: , , — S @ 06:49

In general I do not like factors in my data frames, and while there are good reasons to have them, my work typically does not require it. So when trying to amend or add to data frames using rbind these hidden factors cause problems. The easiest solution I have found is to turn those factors into character vectors using the following code.

 

i <- sapply(df.coords, is.factor)
df.coords[i] <- lapply(df.coords[i], as.character)
df.coords<-rbind(df.coords,my.addition)

2014/08/16

install all packages from task view in R

Filed under: R, R Stats — Tags: , , — S @ 08:13

Use the ctv package to install all of the packages that are listed in an R taskview

library(ctv)
install.views("Spatial")

Create a free website or blog at WordPress.com.