2

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

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:

enter image description here

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.

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.

Thanks!

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
Tim
  • 23
  • 4

1 Answers1

0

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

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.

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Thank you very much for the fast response, this was exactly what I was looking for! I plan on just explaining in the figure caption that the dots at the top represent successful intervals, and the dots at the bottom represent failed intervals, as they do in figure 2 of this paper... http://digitalcommons.unl.edu/cgi/viewcontent.cgi?article=1343&context=natrespapers – Tim Dec 14 '17 at 15:59