0

I'm trying to create a plot in R- one with both data points and a trend line. However, no matter how I change the code, whether it be the type of points or the colour, it only comes up with a very basic scatter graph. I can't change the type, the colour, or anything else. Here is the code I used:

counts = data.frame(year.counts)
counts
yearvec <- counts$Year
countvec <- counts$Number.of.birds
yearvec <- as.factor(yearvec)
plot(yearvec, countvec, type= 'b', xlab = 'Year', ylab = 'Number of birds', col = 'red')

I am a new member so couldn't embed a picture of the graph yet. Is there any reason why my graph comes out as a plain black scatter graph?

  • 1
    Hi, Welcome to SO! I would be helpful to include a [minimal dataset](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) when asking questions. – xilliam Mar 02 '21 at 11:26
  • That said, you probably need to add a line of code that specifies the line with ```abline()``` like demonstrated [here](https://stackoverflow.com/questions/15102254/how-do-i-add-different-trend-lines-in-r) – xilliam Mar 02 '21 at 11:29
  • 1
    Does this answer your question? [How do I add different trend lines in R?](https://stackoverflow.com/questions/15102254/how-do-i-add-different-trend-lines-in-r) – xilliam Mar 02 '21 at 11:31

0 Answers0