线性回归生存图 - 如何改变失败位置(0)点?

时间:2020-12-04 23:41:15

This is my first question I have posted on here so I apologize in advance if I do anything wrong. I am plotting nest survival against a habitat variable (in my case shrub cover surrounding nests) using ggplot2 in R, as outlined here... https://rpubs.com/bbolker/logregexp

这是我在这里发布的第一个问题,所以如果我做错了,我会提前道歉。我正在使用R中的ggplot2绘制巢生存与栖息地变量(在我的情况下,灌木覆盖在巢周围),如此处所述...... https://rpubs.com/bbolker/logregexp

Here is a reproducible example...

这是一个可重复的例子......

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")

This gives me this plot:

这给了我这个情节:

线性回归生存图 - 如何改变失败位置(0)点?

As you can see there is a lot of white space in the plot because it needs to show the failed intervals (periods that the nest did not survive) at zero and the successful intervals at 1.

正如您所看到的,图中有很多空白区域,因为它需要显示失败的间隔(嵌套不存活的时间段)为零,成功的间隔为1。

My question is... how do I move the dots that are at 0 up in the plot (but leave the dots at 1 in the same place) so I can then adjust the y axis and remove all that white space. I tried using position_nudge but that moved both the circles at 0 and circles at 1 by the same distance.

我的问题是......如何在图中移动0点处的点(但是在同一位置将点保持为1),这样我就可以调整y轴并移除所有空白区域。我尝试使用position_nudge但是它将两个圆圈移动到0并且将圆圈移动到相同的距离。

Thanks!

1 个解决方案

#1


0  

If you want to just "move them up", then just change the y value aesthetic for your points

如果你想“向上移动”,那么只需更改你的点的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")

Of course this doesn't really make for a meaningful y-axis any more.

当然,这不再是一个有意义的y轴。

线性回归生存图 - 如何改变失败位置(0)点?

#1


0  

If you want to just "move them up", then just change the y value aesthetic for your points

如果你想“向上移动”,那么只需更改你的点的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")

Of course this doesn't really make for a meaningful y-axis any more.

当然,这不再是一个有意义的y轴。

线性回归生存图 - 如何改变失败位置(0)点?