I have a scatter plot....How to plot centroid in it??
stat_summary(fun = mean)??? or??
I tried the code below but... i need a cluster point?
plot(Period_1_AB, Period_2_AB, pch = 0 , cex = .8)
points(Period_1_BA, Period_2_BA, pch = 2, cex = .8)
abline(0,1)
If I understand you correctly, you can do this by simply plotting the mean using points()
:
Data
set.seed(123)
df <- data.frame(x = runif(100),
y = runif(100))
Plot - here, I plotted the centroid of the points in red.
plot(df, pch = 19)
points(mean(df$x), mean(df$y), pch = 19, col = "red")
Edit: per your comment requesting ggplot2::geom_point
, one way would be:
ggplot(df, aes(x, y)) +
geom_point() +
geom_point(data = data.frame(lapply(df[], mean)),
aes(x = x, y = y), col="red")