我正在尝试制作一个 ggplot 图,它根据另一个(ZONE)使用 显示变量(SIZE)的比例face_grid,然后在每个类别中使用 显示二元变量(BG)的平均值stat_summary。但是现在,我想加入点(均值)并以百分比格式显示均值(靠近点)。为了加入我尝试过的要点stat_summary('arguments here',geom="line")和其他命令,但事实是我不知道该怎么做。
library(ggplot2)
library(scales)
set.seed(100)
data <- data.frame(ID = 1:600,
SIZE = rep(c('B','M','S'), each = 200),
ZONE = sample(c('A','B'), size = 600, replace=T),
BG = c(sample(0:1, size = 200, prob = c(1,1), replace=T),
sample(0:1, size = 200, prob = c(2,3), replace=T),
sample(0:1, size = 200, prob = c(1,2), replace=T)))
ggplot(data, aes(x = SIZE)) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
facet_grid(~ZONE) +
stat_summary(aes(y = BG), fun.y=mean, colour="red", geom="point", size = 3) + …Run Code Online (Sandbox Code Playgroud) 我试图在d3.js中进行链式转换.为此,我在数组中定义了一组转换,并且(尝试)使用函数来递归调用它们.each("end", function()),在前一个完成时启动转换,但我还没有结果.
行动清单
animations = [ function(){ console.log(1); return circle.transition().duration(2e3).attr("cy", Math.random()*300); } ,
function(){ console.log(2); return rect.transition().duration(3e3).attr("fill", "#"+((1<<24)*Math.random()|0).toString(16)); },
function(){ console.log(3); return circle.transition().duration(1e3).attr("r", Math.random()*500); },
function(){ console.log(4); return circle.transition().duration(2e3).style("fill", "#"+((1<<24)*Math.random()|0).toString(16)); },
function(){ console.log(5); return circle.transition().duration(1e3).attr("cx", Math.random()*500); }]
Run Code Online (Sandbox Code Playgroud)
递归函数
function animate(index){
if(index < animations.length - 1){
index = index + 1
return animations[index]().each("end", animate(index))
} else {
return true
}
}
Run Code Online (Sandbox Code Playgroud)
jsfiddle就在这里,这是一个使用recusive函数的例子.
谢谢大家.
...我试图获取函数组合中的名称列表和表达式。我们假设一个函数:
g <- function(...) {
print(as.list(match.call(expand.dots = FALSE))$...)
}
Run Code Online (Sandbox Code Playgroud)
如果我们调用:
g(rnorm(5), par = "a", 4 + 4)
Run Code Online (Sandbox Code Playgroud)
我们得到:
[[1]]
rnorm(5)
$par
[1] "a"
[[3]]
4 + 4
Run Code Online (Sandbox Code Playgroud)
这很好:我们可以获取每个参数的表达式调用并进行验证。但我需要这个,但在函数组合中:
f <- function(...) g(...)
f(rnorm(5), par = "a", 4 + 4)
Run Code Online (Sandbox Code Playgroud)
但我得到:
[[1]]
..1
$par
[1] "a"
[[3]]
..3
Run Code Online (Sandbox Code Playgroud)
我正在阅读一些章节http://adv-r.had.co.nz/Expressions.html,但我还找不到解决方案。我知道,我需要继续学习。
有小费吗?提前致谢。