Is it possible to identify data points above a geom_abline
in ggplot, and to create a new data table separating these data points using data.table
?
I have a panel dataset with 150 unique ID
's, and have fit a fixed effects model using plm(). Here is a sample of the dataset:
data <- data.frame(ID = c(1,1,1,1,2,2,3,3,3),
year = c(1,2,3,4,1,2,1,2,3),
progenyMean = c(90,78,92,69,86,73,82,85,91),
damMean = c(89,89,72,98,95,92,94,87,89)
ID, year, progenyMean, damMean
1, 1, 70, 69
1, 2, 68, 69
1, 3, 72, 72
1, 4, 69, 68
2, 1, 76, 75
2, 2, 73, 80
3, 1, 72, 74
3, 2, 75, 67
3, 3, 71, 69
# Fixed Effects Model in plm
fixed <- plm(progenyMean ~ damMean, data, model= "within", index = c("ID","year"))
I have plotted the response progenyMean
vs damMean
using the following code:
plotFunction <- function(aggData, year){
ggplot(aggData, aes(x=damMeanCentered, y=progenyMean3Y)) +
geom_point() +
geom_abline(slope=fixed$coefficients, intercept=71.09, colour='dodgerblue1', size=1)
# The intercept 71.09 was calculated using the mean of fixef(fixed)
}
plotFunction(data, '(2005 - 2012)')
Is it possible to identify the points above/below the geom_abline
in ggplot and create a new data table separating these data points using data.table
?