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
# http://blog.goo.ne.jp/r-de-r/e/c9cc759642ea0c02560bd08c975fb156 | |
b = 0.111111 * 1:9 # b は 0.111111 ~ 0.999999 の 9 種類 | |
bz = b+0.000001 | |
b2 = 2 * b | |
bz2 = 2*bz | |
b.sq = b ^ 2 | |
bz.sq = bz ^ 2 | |
n = 10000 # 探索範囲上限 | |
ansa = c() |
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
library(gtable) | |
d=data.frame(g=c(1,1,1,2,2,3),x=c(1,2,3,1,2,3),y=1:6); | |
p = ggplot(d,aes(x,y))+geom_bar(stat="identity")+facet_wrap(~g) | |
gt= ggplot_gtable(ggplot_build(g)) | |
graphics.off() | |
for (p in c(4, 7, 10)) { | |
pdf(paste0("plot-", p, ".pdf")) | |
grid.draw(gt[,c(1:3, p, 12)]) |
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
graphics.off() | |
W <- 5.5 | |
H <- 5.5 | |
parts <- function(x0, y0, BLfin, Size) { | |
Nfin <- 48 | |
BLfin <- c(BLfin, 1-BLfin) | |
FSize <- 1 |
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
library(plyr) | |
library(ggplot2) # needs dev version of ggplot2 for the colorbar | |
if(0){ | |
locs <- getCountriesFromGoogle(country="JP") | |
weas <- llply(locs$name, function(l) { | |
r <- NULL | |
try(r <- getWeatherFromGoogle(l)) | |
r | |
}) |