【发布时间】:2017-10-19 13:23:01
【问题描述】:
以下代码可以满足我对两个简化图的需求,但需要一个幻数来表示 y 位置而不是计算(已注释掉)。
df1 <- data.frame(y=c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE),
x=c(1,2,3,4,5,6,7,8,9))
df2 <- data.frame(y=c(1,1,0,1,0,1,0,0,0),
x=c(1,2,3,4,5,6,7,8,9))
# yplace <- mean(as.numeric(levels(as.factor(df$y))))
yplace1 <- 1.5
yplace2 <- 0.5
library(ggplot2)
ggplot(data=df1, aes(x=x,y=y)) + geom_point() +
annotate("text", label="read me", x=mean(df1$x), y=yplace1)
ggplot(data=df2, aes(x=x,y=y)) + geom_point() +
annotate("text", label="read me", x=mean(df2$x), y=yplace2)
我正在尝试编写一个通用函数,它将注释放置在任何二项式散点图的中心。注释掉的 yplace 分配是我想到的最接近的东西,但它导致 TRUE/FALSE 分布的 NA 。如果 y 向量都是 1 和 0,并且所有 TRUE 和 FALSE 都返回 1.5,我是否可以使用一个函数或计算来返回 0.5?我想不出任何其他常用的二项分布,但处理 y 向量包含两个因子的任何情况都是理想的。
【问题讨论】: