This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p <- ggplot(melt(outer(1:4, 1:4)), aes(x=X1, y=X2)) + geom_tile(aes(fill=value)) | |
# default legend | |
png("guide_%02d.png", width=350, height=350) | |
p | |
# colorbar legend (vertical) | |
p + scale_fill_continuous(guide="colorbar") | |
# colorbar legend (horizontal) | |
p + scale_fill_continuous(guide="colorbar") + opts(legend.position="bottom", legend.direction="horizontal") | |
# change the size of legend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p <- function()ggplot(melt(outer(1:4, 1:4)), aes(x = X1, y = X2)) + geom_tile(aes(fill = value)) | |
p2 <- function()ggplot(melt(outer(1:4, 1:4)), aes(x = X1, y = X2)) + geom_tile(aes(fill = value)) + geom_point(aes(size = value)) | |
## legend | |
p() | |
## direction of guide | |
p() + opts(legend.direction = "horizontal") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g <- ggplot(mtcars, aes(cyl, mpg)) + geom_point() + stat_summary(fun.y=mean, geom="line") | |
d <- print(g) | |
## look up data from "stat" | |
get_data_from_stat <- function(gobj, stat) Find(function(x)attr(x, "stat")==stat, gobj$data) | |
## look up data from "geom" | |
get_data_from_geom <- function(gobj, geom) Find(function(x)attr(x, "geom")==geom, gobj$data) | |
get_data_from_stat(d, "summary") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lims <- data.frame(vs=c(0,0,1,1), am=c(0,1,0,1), | |
xmin=c(6,2,2,2), xmax=c(10,10,6,4), ymin=c(10,15,17,21),ymax=c(20,26,25,34)) | |
#ggplot(mtcars, aes(cyl, mpg)) + geom_point() + | |
# facet_grid(~vs+am, scale="free", lims=lims) # does not work with facet_grid | |
ggplot(mtcars, aes(cyl, mpg)) + geom_point() + | |
facet_wrap(~vs+am, scale="free", coord.limits=lims) + coord_cartesian(wise=T) # please try also wise=F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(1) | |
x <- rnorm(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## -------------------------------- | |
## from guides.R | |
## -------------------------------- | |
# ggplot object | |
dat <- data.frame(x=1:5, y=1:5, p=1:5, q=factor(1:5), r=factor(1:5)) | |
p <- function()ggplot(dat, aes(x, y, colour=p, size=q, shape=r)) + geom_point() | |
# without guide specificatoin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p <- qplot(1:20, 1:20, col=letters[1:20]) | |
p + guides(col=guide_legend(nrow=8)) | |
p + guides(col=guide_legend(ncol=8)) | |
p + guides(col=guide_legend(nrow=8, byrow=T)) | |
p + guides(col=guide_legend(ncol=8, byrow=T)) | |
# output plots: http://yfrog.com/klhjpwp | |
# how to embed images in gist...? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install devtools | |
install.packages('devtools') | |
# install dependency of scales package | |
install.packages(c("RColorBrewer", "stringr", "dichromat", "munsell", "plyr", "colorspace")) | |
# load devtools | |
library(devtools) | |
# move to development mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test with R 2.14.0 and ggplot2 0.8.9 | |
library(ggplot2) | |
# define stat_aggr2d | |
StatAggr2d <- proto(Stat, { | |
objname <- "aggr2d" | |
default_aes <- function(.) aes(fill = ..value..) | |
required_aes <- c("x", "y", "z") | |
default_geom <- function(.) GeomRect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
graphics.off() | |
W <- 5.5 | |
H <- 5.5 | |
parts <- function(x0, y0, BLfin, Size) { | |
Nfin <- 48 | |
BLfin <- c(BLfin, 1-BLfin) | |
FSize <- 1 |
OlderNewer