Skip to content

Instantly share code, notes, and snippets.

@suncoolsu
suncoolsu / getMinMax_with_without_as.name.r
Created December 6, 2010 09:40
Using as.name in ddply .(variable) results in an error "object 'grp' not found"
## Doesn't work
# grp -- name of a column of the the data.frame df
# function call is -- getMinMax1( df1 , grp = "g10")
getMinMax1 <-function(df, grp){
dfret <- ddply( df , .(as.name(grp)), ## I am using as.name(grp), source of error
function(x){
minmax <- c(mix(x[ , 3]), max(x[ ,3]))
return(minmax)
@suncoolsu
suncoolsu / keylabels.R
Created February 6, 2011 10:04
How do I change the key labels in this plot?
qplot(depth, data=diamonds, geom="density", xlim = c(54, 70),
fill = cut, alpha = I(0.2)) +
labs(fill = "My Style \nDensity Plot" )