From 9fcaa52bd0af2deaa7d0599e167d3a0e82409a66 Mon Sep 17 00:00:00 2001 From: Jake Russ Date: Tue, 14 Jun 2011 13:27:55 -0400 Subject: [PATCH] Style changes for consistent code --- R/facet-grid-.r | 8 ++++---- R/facet-wrap.r | 8 ++++---- R/geom-bar-.r | 14 +++++++------- R/geom-boxplot.r | 15 +++++++-------- R/geom-text.r | 4 ++-- man/facet_grid.Rd | 6 +++--- man/facet_wrap.Rd | 6 +++--- man/geom_bar.Rd | 14 +++++++------- man/geom_boxplot.Rd | 7 +++---- man/geom_text.Rd | 4 ++-- 10 files changed, 42 insertions(+), 44 deletions(-) diff --git a/R/facet-grid-.r b/R/facet-grid-.r index a362cb5c92..b73518e408 100644 --- a/R/facet-grid-.r +++ b/R/facet-grid-.r @@ -21,12 +21,12 @@ #' p + facet_grid(cut ~ clarity) #' p + facet_grid(cut ~ clarity, margins=TRUE) #' -#' #To change plot order of facet grid, -#' #change the order of varible levels with factor() +#' # To change plot order of facet grid, +#' # change the order of varible levels with factor() #' diamonds$cut <- factor(diamonds$cut, levels = c("Ideal","Very Good","Fair", "Good", "Premium")) -#' #Repeat first example with new order +#' # Repeat first example with new order #' p <- ggplot(diamonds, aes(carat, ..density..)) + -#' geom_histogram(binwidth = 1) +#' geom_histogram(binwidth = 1) #' p + facet_grid(. ~ cut) #' #' qplot(mpg, wt, data=mtcars, facets = . ~ vs + am) diff --git a/R/facet-wrap.r b/R/facet-wrap.r index aaa7c2e919..6617e84852 100644 --- a/R/facet-wrap.r +++ b/R/facet-wrap.r @@ -19,12 +19,12 @@ #' # plots into 2d - the ribbon just gets longer #' # d + facet_wrap(~ color + cut) #' -#' #To change plot order of facet wrap, -#' #change the order of varible levels with factor() +#' # To change plot order of facet wrap, +#' # change the order of varible levels with factor() #' diamonds$color <- factor(diamonds$color, levels = c("G","J","D", "E", "I", "F", "H")) -#' #Repeat first example with new order +#' # Repeat first example with new order #' d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + -#' xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1) +#' xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1) #' d + facet_wrap(~ color) #' #' # You can choose to keep the scales constant across all panels diff --git a/R/geom-bar-.r b/R/geom-bar-.r index 32e72171d5..f21f692589 100644 --- a/R/geom-bar-.r +++ b/R/geom-bar-.r @@ -90,15 +90,15 @@ #' qplot(cut, meanprice, geom="bar", stat="identity") #' qplot(cut, meanprice, geom="bar", stat="identity", fill = I("grey50")) #' -#' #Another stacked bar chart example +#' # Another stacked bar chart example #' k <- ggplot(mpg, aes(manufacturer, fill=class)) #' k + geom_bar() -#' #Alternative method of changing aesthetics defaults -#' #Change fill color; see ?set_default_scale for more -#' set_default_scale("fill", "discrete", "brewer") -#' k + geom_bar() -#' #To change plot order of class varible -#' #use factor() to change order of levels +#' # Use scales to change aesthetics defaults +#' k + geom_bar() + scale_fill_brewer() +#' k + geom_bar() + scale_fill_grey() +#' +#' # To change plot order of class varible +#' # use factor() to change order of levels #' mpg$class <- factor(mpg$class, levels = c("midsize", "minivan", #' "suv", "compact", "2seater", "subcompact", "pickup")) #' m <- ggplot(mpg, aes(manufacturer, fill=class)) diff --git a/R/geom-boxplot.r b/R/geom-boxplot.r index 42050b407b..cfb08df892 100644 --- a/R/geom-boxplot.r +++ b/R/geom-boxplot.r @@ -51,14 +51,13 @@ #' qplot(year, budget, data = movies, geom = "boxplot", #' group = round_any(year, 10, floor)) #' -#' #Using precomputed statistics -#' #generate sample data -#' abc <- adply(matrix( rnorm(100), ncol=5), 2 , quantile, c(0, .25, .5, .75, 1)) -#' b <- ggplot(abc, aes(x= X1, ymin=`0%`, lower=`25%`, middle=`50%`, -#' upper=`75%`, ymax=`100%`)) -#' b + geom_boxplot(stat="identity") -#' b + geom_boxplot(stat="identity") + coord_flip() -#' b + geom_boxplot(aes(fill = X1), stat="identity") +#' # Using precomputed statistics +#' # generate sample data +#' abc <- adply(matrix( rnorm(100), ncol=5), 2 , quantile, c(0, .25, .5, .75, 1)) +#' b <- ggplot(abc, aes(x= X1, ymin=`0%`, lower=`25%`, middle=`50%`, upper=`75%`, ymax=`100%`)) +#' b + geom_boxplot(stat="identity") +#' b + geom_boxplot(stat="identity") + coord_flip() +#' b + geom_boxplot(aes(fill = X1), stat="identity") GeomBoxplot <- proto(Geom, { objname <- "boxplot" diff --git a/R/geom-text.r b/R/geom-text.r index 448eade134..f737de8af1 100644 --- a/R/geom-text.r +++ b/R/geom-text.r @@ -30,9 +30,9 @@ #' p + geom_text(aes(label = paste(wt, "^(", cyl, ")", sep = "")), #' parse = T) #' -#' #Add an annotation not from a variable source +#' # Add an annotation not from a variable source #' c <- ggplot(mtcars, aes(wt, mpg)) + geom_point() -#' c + geom_text(aes(5, 30, label="plot mpg vs wt")) +#' c + geom_text(aes(5, 30, label="plot mpg vs. wt")) #' #' # Use qplot instead #' qplot(wt, mpg, data = mtcars, label = rownames(mtcars), diff --git a/man/facet_grid.Rd b/man/facet_grid.Rd index 8d1ef2db4c..7063988e71 100644 --- a/man/facet_grid.Rd +++ b/man/facet_grid.Rd @@ -29,10 +29,10 @@ p + facet_grid(clarity ~ cut) p + facet_grid(cut ~ clarity) p + facet_grid(cut ~ clarity, margins=TRUE) -#To change plot order of facet grid, -#change the order of varible levels with factor() +# To change plot order of facet grid, +# change the order of varible levels with factor() diamonds$cut <- factor(diamonds$cut, levels = c("Ideal","Very Good","Fair", "Good", "Premium")) -#Repeat first example with new order +# Repeat first example with new order p <- ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(binwidth = 1) p + facet_grid(. ~ cut) diff --git a/man/facet_wrap.Rd b/man/facet_wrap.Rd index 0f869da02e..2749991be7 100644 --- a/man/facet_wrap.Rd +++ b/man/facet_wrap.Rd @@ -26,10 +26,10 @@ d + facet_wrap(~ color, nrow = 3) # plots into 2d - the ribbon just gets longer # d + facet_wrap(~ color + cut) -#To change plot order of facet wrap, -#change the order of varible levels with factor() +# To change plot order of facet wrap, +# change the order of varible levels with factor() diamonds$color <- factor(diamonds$color, levels = c("G","J","D", "E", "I", "F", "H")) -#Repeat first example with new order +# Repeat first example with new order d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1) d + facet_wrap(~ color) diff --git a/man/geom_bar.Rd b/man/geom_bar.Rd index df6b17e732..f9103641e8 100644 --- a/man/geom_bar.Rd +++ b/man/geom_bar.Rd @@ -99,15 +99,15 @@ qplot(cut, meanprice) qplot(cut, meanprice, geom="bar", stat="identity") qplot(cut, meanprice, geom="bar", stat="identity", fill = I("grey50")) -#Another stacked bar chart example +# Another stacked bar chart example k <- ggplot(mpg, aes(manufacturer, fill=class)) k + geom_bar() -#Alternative method of changing aesthetics defaults -#Change fill color; see ?set_default_scale for more -set_default_scale("fill", "discrete", "brewer") -k + geom_bar() -#To change plot order of class varible -#use factor() to change order of levels +# Use scales to change aesthetics defaults +k + geom_bar() + scale_fill_brewer() +k + geom_bar() + scale_fill_grey() + +# To change plot order of class varible +# use factor() to change order of levels mpg$class <- factor(mpg$class, levels = c("midsize", "minivan", "suv", "compact", "2seater", "subcompact", "pickup")) m <- ggplot(mpg, aes(manufacturer, fill=class)) diff --git a/man/geom_boxplot.Rd b/man/geom_boxplot.Rd index f32ec4c707..da0158f115 100644 --- a/man/geom_boxplot.Rd +++ b/man/geom_boxplot.Rd @@ -55,11 +55,10 @@ qplot(year, budget, data = movies, geom = "boxplot") qplot(year, budget, data = movies, geom = "boxplot", group = round_any(year, 10, floor)) -#Using precomputed statistics -#generate sample data +# Using precomputed statistics +# generate sample data abc <- adply(matrix( rnorm(100), ncol=5), 2 , quantile, c(0, .25, .5, .75, 1)) -b <- ggplot(abc, aes(x= X1, ymin=`0\%`, lower=`25\%`, middle=`50\%`, -upper=`75\%`, ymax=`100\%`)) +b <- ggplot(abc, aes(x= X1, ymin=`0\%`, lower=`25\%`, middle=`50\%`, upper=`75\%`, ymax=`100\%`)) b + geom_boxplot(stat="identity") b + geom_boxplot(stat="identity") + coord_flip() b + geom_boxplot(aes(fill = X1), stat="identity")} diff --git a/man/geom_text.Rd b/man/geom_text.Rd index b9c87ee223..099d1c01b3 100644 --- a/man/geom_text.Rd +++ b/man/geom_text.Rd @@ -34,9 +34,9 @@ p + geom_text(aes(size=wt)) + scale_size(range=c(3,6)) p + geom_text(aes(label = paste(wt, "^(", cyl, ")", sep = "")), parse = T) -#Add an annotation not from a variable source +# Add an annotation not from a variable source c <- ggplot(mtcars, aes(wt, mpg)) + geom_point() -c + geom_text(aes(5, 30, label="plot mpg vs wt")) +c + geom_text(aes(5, 30, label="plot mpg vs. wt")) # Use qplot instead qplot(wt, mpg, data = mtcars, label = rownames(mtcars),