Search code examples
rggplot2smoothing

How to plot occupation probability?


I am currently stucked with the following problem. I collected data of bat boxes and checked whether bats were present in the box or not (0=not present, 1=present). Now I want to plot the probability of occupation on the y-axis and the proportion of tree coverage in a 500m radius around the bat box on the x-axis.

I could not find any hint how to do it and have no clue as well.

This is a part of the data (so you see: with increasing tree coverage the bat boxes are rather used by bats and that is what I want to plot (I thought maybe a geom_smooth would be good)

Tree Cover (%)   Occupation

11,25806         0 

9,84961          0    

9,77807          1

14,89228         0

14,38696         0

14,40911         0

14,24987         0

18,43799         1

20,28749         0

20,13795         1

19,87961         0

22,14027         1

46,17592         1

46,82814         1 

28,36949         0

28,40777         1

I am thankful for every idea!


Solution

  • This seems like a classic problem for a glm. You can plot the glm results directly in ggplot:

    ggplot(d, aes(Tree_Cover, Occupation)) +
      geom_smooth(method = 'glm', method.args = list(family = 'binomial')) +
      geom_point(shape = '|', size = 8, alpha = 0.3)
    

    enter image description here

    The y-axis denotes the probability that a bat box is occupied, depending on the tree cover. Vertical bars correspond to raw observations.