Skip to content

Instantly share code, notes, and snippets.

View GuangchuangYu's full-sized avatar
🎯
Focusing

Guangchuang Yu GuangchuangYu

🎯
Focusing
View GitHub Profile
@GuangchuangYu
GuangchuangYu / jiong.R
Created February 17, 2012 09:13
draw chinese character Jiong using ggplot2
f <- function(x) 1/(x^2-1)
x <- seq(-3,3, by=0.001)
y <- f(x)
d <- data.frame(x=x,y=y)
p <- ggplot()
p <- p+geom_rect(fill = "white",color="black",size=3,
aes(NULL, NULL,xmin=-3, xmax=3,
ymin=-3,ymax=3, alpha=0.1))
@GuangchuangYu
GuangchuangYu / valetine.R
Created February 14, 2012 05:38
generate heart plot for valentine's day
require(ggplot2)
t <- seq(0,2*pi, by=0.1)
x <- 16*sin(t)^3
y <- 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)
d <- data.frame(x=x,y=y, f=0)
a <- x
b <- y
@GuangchuangYu
GuangchuangYu / fibonacci.R
Created February 9, 2012 05:32
calculating fibonacci number
fibonacci <- function(n) {
u <- (1+sqrt(5))/2
(u^n - (1-u)^n) / sqrt(5)
}
@GuangchuangYu
GuangchuangYu / violin_plot.R
Created February 8, 2012 03:51
generate violin plot using ggplot2
p <- ggplot(mtcars, aes(factor(cyl),mpg,
fill=factor(cyl),
colour=factor(cyl)))
p1 <- p+geom_violin(alpha=0.3, width=0.5) +
geom_boxplot(width=0.2, outlier.colour=NA)
p2 <- p+geom_violin(alpha=0.3, width=0.5) +
geom_dotplot(binaxis='y', stackdir='center', dotsize=0.5)