Count points in each quadrant of a scatterplot [closed]

I'm an R noob, please bear with me.

I'm using R to plot data in a scatterplot along with 2 gridlines separating the plot into 4 quadrants. I'd like to count the number of data points in each quadrant. How might I do this?

closed as off-topic by Michael Chernick, whuber♦Jan 4 '18 at 0:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael Chernick, whuber
If this question can be reworded to fit the rules in the help center, please edit the question.

• Beauty! @hxd1011 – Spagooters Jan 4 '18 at 0:23

The table function in R provide us a simpler way of doing the same thing as @Mark White suggested.

A simpler code table(x>0, y>0) will build a 2D table of the on four quadrants.

Once you define what the values determining the quadrants are (here, x = 0 and y = 0), you can use the operators <, >, and & to get values that are TRUE or FALSE if the case lies in that quadrant. Since R stores TRUE as 1 and FALSE as 0, you can simply sum across these to see how many are in each quadrant. Try this:

set.seed(1839)
x <- rnorm(100)
y <- rnorm(100)

plot(x, y)
abline(h = 0)
abline(v = 0)

quadrant_1 <- sum((x < 0) & (y < 0))

• 'table(x>0, y>0) most R way of doing it :) – hxd1011 Jan 3 '18 at 21:17