Skip to content

Instantly share code, notes, and snippets.

@kazutan
Last active August 29, 2015 14:25
Show Gist options
  • Save kazutan/2edbb8b98bd332fc88c5 to your computer and use it in GitHub Desktop.
Save kazutan/2edbb8b98bd332fc88c5 to your computer and use it in GitHub Desktop.
# lapplyでgeom_segment()を繰り返し記述
p <- ggplot(iris, aes(y=Sepal.Width, x=Species)) +
stat_summary(fun.y=mean, geom = "bar") +
ylim(0,6) +
lapply(1:3, function(i) geom_segment(x=i-0.4, y=7-i, xend=i+0.4, yend=7-i))
p
# あと教えてもらったmapply使ったサンプルコードメモ
q = ggplot(data.frame(x = c(-10, 10)), aes(x)) +
mapply(function(m, s, co) stat_function(fun = dnorm, args = list(mean = m, sd = s), colour = co),
-1:1, c(0.5, 1, 1.5), rainbow(3))
q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment