I am trying to plot presence/absence (1/0) of a sample species against various environmental variables.

I have put presence/absence on the y-axis and the environmental variable (in this case barometric pressure) on the x axis, however the resulting plot looks terrible.

Scatterplot of presence (1) and absence (0) against barometric pressure

Is there a better way to do this? I thought of plotting presence/absence against the frequency of the environmental variable, would this be possible?

  • $\begingroup$ Two histograms or two stripplots or two quantile plots? $\endgroup$
    – Nick Cox
    Commented Jun 17, 2018 at 15:23
  • 1
    $\begingroup$ Typical approach is to visualize the distribution within factor level e.g. by boxplots and then compare. $\endgroup$
    – Michael M
    Commented Jun 17, 2018 at 18:04
  • $\begingroup$ Those points look like they only come at discrete levels, or were rounded. Is that true? Are there multiple data points that are stacked on top of each other, or are represented by a single plotted point in this figure? $\endgroup$ Commented Jun 18, 2018 at 1:23

2 Answers 2


If I understood the question correctly - you might want to use a "conditional density plot".

Such a plot provides a smoothed overview of how a categorical variable changes across various levels of continuous numerical variable.


For a real-world example here is the distribution of Sepal Width across 3 different species in the iris dataset:

cdplot(Species ~ Sepal.Width, data=iris)

enter image description here


These plots represent smoothed proportions of each category within various levels of the continuous variable. In order to interpret them you should look across at the x-axis and see how the different proportions for each category (represented by different colors) change with the different values of the numerical variable.

For example consider the picture above: it is quite easy to see that when sepal width reaches 3.5 or above you are most likely dealing with setosa type of flower. At sepal width 2.0 the versicolor dominates. And at 3.0 there are about 20% setosa, 35% versicolor and 45% virginica (judging by eye according to the scales on the y-axis on the right.)

For another discussion about interpretation of such plots consider reading answers in this question: Interpretation of conditional density plots

Your case

Of course in your case you would have 2 categories on the y-axis. So the final picture would look closer to this example:


presence <- factor(rbinom(20, 1, 0.5))
 [1] 0 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 1 1 1
Levels: 0 1

pressure <- runif(20, 1000, 1035)
 [1] 1012.282 1014.687 1021.619 1024.159 1026.247 1021.663 1013.469 
     1018.317 1024.054 1002.747 1028.396 1004.806 1033.906 1022.898 
     1033.127 1004.378 1019.386 1016.432 1030.160 1021.567

cdplot(presence ~ pressure)

enter image description here

Interpretation stays the same, except you will be dealing with a binary categorical variable. In this particular case the plot would suggest that the presence (1, light grey area) is increasing with increasing values of pressure (x-axis).


Much better to turn your plot around: put presence on the horizontal and pressure on the vertical axis. Then plot pressure as a dotplot. If overplotting is an issue, jitter the dots horizontally.

If you want to emphasize the distribution and/or summary statistics, overlay a boxplot or a beanplot.

Of course you can plot these horizontally, too, if you insist, but for just two groups, one usually sees the vertical versions below.




n_per_group <- 30
pressure <- data.frame(F=rnorm(n_per_group,1000,20),T=rnorm(n_per_group,1000,20))

    xlab="Presence",ylab="Pressure (hPa)")

beanplot(pressure,what=c(0,1,0,0),col="gray",xaxt="n",xlab="Presence",ylab="Pressure (hPa)")
  • 1
    $\begingroup$ I always do these horizontally in this case, just to maintain a closer analogy. $\endgroup$ Commented Jun 18, 2018 at 1:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.