1
votes

I would like to add a label for each Year [2008-2017] for mean of Distance_m (Distance in meters) vs mean of RAI_CS (Relative Abundance Indices per Camera Station). I used plot and ggplot but have had no success.

I tried this code using plot.

plot(tapply(MyData$RAI_CS, MyData$Year, mean)~tapply(MyData$Distance_m, MyData$Year, mean), MyData)

I cannot get the label=Year to work. I come close with this code but cannot get the labels for each year to show, only data points of means, unhelpful as I don't know which year is which.

I tried this code in ggplot.

ggplot(MyData, aes(x=mean(MyData$Disctance_m), y=mean(MyData$RAI_CS), label=MyData$Year))+ geom_point()

I get this warning message for ggplot Warning messages:

1: In mean.default(MyData$Disctance_m) : argument is not numeric or logical: returning NA
2: In mean.default(MyData$Disctance_m) : argument is not numeric or logical: returning NA
3: Removed 2938 rows containing missing values (geom_point).

However, my data is numeric despite this warning. I want the mean distance vs mean RAI and one data point for each year to be labelled with the year on the plot.

1
Can you please share a reproducible example, what your dataframe looks like ?user12052711
Could you add a sample of your data with dput? Avoid $ in the tidyverse and also check that Distance* or RAI* is indeed numeric.NelsonGon

1 Answers

2
votes

Taking Iris dataset as an example, since dataset details are not provided please try to run below & understand, using geom_text to add labels to geom_point

data("iris")
library(ggplot2)

ggplot(iris, aes(Sepal.Length, Sepal.Width))+
  geom_point()+
  geom_text(aes(label=Species))