线性回归生存图 - 如何改变失败(0)点的位置?
Linear regression survival plot - how to change position of failure (0) dots?
这是我在这里发布的第一个问题,所以如果我做错了什么,我提前道歉。我正在使用 R 中的 ggplot2 针对栖息地变量(在我的例子中是灌木覆盖的巢穴)绘制巢穴存活率,如此处概述...
https://rpubs.com/bbolker/logregexp
这是一个可重现的例子...
library(ggplot2)
nest_data <- structure(list(Exposure = c(5L, 5L, 2L, 6L, 2L, 4L, 1L, 3L, 3L, 6L, 2L, 6L, 4L, 5L, 3L, 7L, 7L, 5L, 4L, 8L, 4L, 8L, 1L, 5L, 7L, 3L, 6L, 5L, 7L, 10L, 5L, 6L, 5L, 4L, 8L, 6L, 5L, 6L, 7L, 7L, 7L, 7L, 5L, 7L, 8L, 3L, 5L, 5L, 6L, 6L, 5L, 2L, 2L, 6L, 4L, 6L, 6L, 5L, 4L, 8L), Surv = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L), shr5 = c(60, 60, 71.25, 43.75, 43.75, 91.25, 33.75, 83.75, 82.5, 82.5, 82.5, 67.5, 72.5, 72.5, 23.75, 92.5, 78.75, 58.75, 42.5, 42.5, 40, 40, 94.75, 60, 60, 60, 21.25, 92, 92, 100, 100, 100, 97.5, 46.25, 46.25, 65.25, 65.25, 72.5, 72.5, 53.75, 43.75, 43.75, 82.75, 82.75, 57.5, 57.5, 52.5, 52.5, 98.75, 98.75, 88.75, 88.75, 61.25, 95.75, 90, 100, 100, 77.5, 40, 40)), .Names = c("Exposure", "Surv", "shr5"), class = "data.frame", row.names = c(699L, 700L, 709L, 718L, 719L, 724L, 727L, 732L, 740L, 741L, 742L, 746L, 750L, 751L, 753L, 757L, 770L, 777L, 781L, 782L, 786L, 787L, 790L, 802L, 803L, 807L, 811L, 821L, 822L, 826L, 827L, 828L, 829L, 840L, 841L, 846L, 847L, 858L, 859L, 867L, 872L, 873L, 874L, 875L, 878L, 879L, 883L, 884L, 888L, 889L, 897L, 898L, 901L, 905L, 911L, 915L, 916L, 920L, 921L, 922L))
ggplot(nest_data,aes(x=shr5,y=Surv)) +
geom_point(aes(size=Exposure), shape=1) +
geom_smooth(method="glm", col="black") +
theme_bw() +
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +
xlab("Shrub cover") +
ylab("Survival") +
scale_size("Exposure days")
这给了我这个情节:
如您所见,图中有很多白色 space,因为它需要在 0 处显示失败间隔(巢未存活的时间段),在 1 处显示成功间隔。
我的问题是...如何将图中 0 处的点向上移动(但将 1 处的点留在同一位置)以便我可以调整 y 轴并移除所有白色space。我尝试使用 position_nudge,但将 0 处的圆圈和 1 处的圆圈移动了相同的距离。
谢谢!
如果您只想 "move them up",那么只需更改 y
点数的审美价值
ggplot(nest_data,aes(x=shr5,y=Surv)) +
geom_point(aes(y=ifelse(Surv==0, .6, Surv), size=Exposure), shape=1) +
geom_smooth(method="glm", col="black") +
theme_bw() +
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +
xlab("Shrub cover") +
ylab("Survival") +
scale_size("Exposure days")
当然,这不再真正构成有意义的 y 轴。
这是我在这里发布的第一个问题,所以如果我做错了什么,我提前道歉。我正在使用 R 中的 ggplot2 针对栖息地变量(在我的例子中是灌木覆盖的巢穴)绘制巢穴存活率,如此处概述... https://rpubs.com/bbolker/logregexp
这是一个可重现的例子...
library(ggplot2)
nest_data <- structure(list(Exposure = c(5L, 5L, 2L, 6L, 2L, 4L, 1L, 3L, 3L, 6L, 2L, 6L, 4L, 5L, 3L, 7L, 7L, 5L, 4L, 8L, 4L, 8L, 1L, 5L, 7L, 3L, 6L, 5L, 7L, 10L, 5L, 6L, 5L, 4L, 8L, 6L, 5L, 6L, 7L, 7L, 7L, 7L, 5L, 7L, 8L, 3L, 5L, 5L, 6L, 6L, 5L, 2L, 2L, 6L, 4L, 6L, 6L, 5L, 4L, 8L), Surv = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L), shr5 = c(60, 60, 71.25, 43.75, 43.75, 91.25, 33.75, 83.75, 82.5, 82.5, 82.5, 67.5, 72.5, 72.5, 23.75, 92.5, 78.75, 58.75, 42.5, 42.5, 40, 40, 94.75, 60, 60, 60, 21.25, 92, 92, 100, 100, 100, 97.5, 46.25, 46.25, 65.25, 65.25, 72.5, 72.5, 53.75, 43.75, 43.75, 82.75, 82.75, 57.5, 57.5, 52.5, 52.5, 98.75, 98.75, 88.75, 88.75, 61.25, 95.75, 90, 100, 100, 77.5, 40, 40)), .Names = c("Exposure", "Surv", "shr5"), class = "data.frame", row.names = c(699L, 700L, 709L, 718L, 719L, 724L, 727L, 732L, 740L, 741L, 742L, 746L, 750L, 751L, 753L, 757L, 770L, 777L, 781L, 782L, 786L, 787L, 790L, 802L, 803L, 807L, 811L, 821L, 822L, 826L, 827L, 828L, 829L, 840L, 841L, 846L, 847L, 858L, 859L, 867L, 872L, 873L, 874L, 875L, 878L, 879L, 883L, 884L, 888L, 889L, 897L, 898L, 901L, 905L, 911L, 915L, 916L, 920L, 921L, 922L))
ggplot(nest_data,aes(x=shr5,y=Surv)) +
geom_point(aes(size=Exposure), shape=1) +
geom_smooth(method="glm", col="black") +
theme_bw() +
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +
xlab("Shrub cover") +
ylab("Survival") +
scale_size("Exposure days")
这给了我这个情节:
如您所见,图中有很多白色 space,因为它需要在 0 处显示失败间隔(巢未存活的时间段),在 1 处显示成功间隔。
我的问题是...如何将图中 0 处的点向上移动(但将 1 处的点留在同一位置)以便我可以调整 y 轴并移除所有白色space。我尝试使用 position_nudge,但将 0 处的圆圈和 1 处的圆圈移动了相同的距离。
谢谢!
如果您只想 "move them up",那么只需更改 y
点数的审美价值
ggplot(nest_data,aes(x=shr5,y=Surv)) +
geom_point(aes(y=ifelse(Surv==0, .6, Surv), size=Exposure), shape=1) +
geom_smooth(method="glm", col="black") +
theme_bw() +
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +
xlab("Shrub cover") +
ylab("Survival") +
scale_size("Exposure days")
当然,这不再真正构成有意义的 y 轴。