-1

I have a data set which describes the start, maximum and end of a vegetation season as day of year over 18 years like this:

Year   Day of Green  Var Green  Day Max  Day Senesc  Var Senesc  Veg Length
2000   111           4          137      253         11          142
2001   115           5          158      252         19          137
2002   110           4          136      263         10          153
2003   112           3          143      271         16          159
2004   105           4          142      279         13          174
2005   106           5          156      278         11          172

Now I want a plot, which shows the years as xaxis and a yaxis with Day of Year(DOY). So I can pinpoint days of greening, maximum greening and browning (senescence).

Thank you for your ideas.

Bari
  • 53
  • 5

2 Answers2

1

Not sure what issues you're running into but here's a way to get that plot using ggplot:

DATA

structure(list(Year = 2000:2005, Day.of.Green = c(111L, 115L, 
110L, 112L, 105L, 106L), Var.Green = c(4L, 5L, 4L, 3L, 4L, 5L
), Day.Max = c(137L, 158L, 136L, 143L, 142L, 156L), Day.Senesc = c(253L, 
252L, 263L, 271L, 279L, 278L), Var.Senesc = c(11L, 19L, 10L, 
16L, 13L, 11L), Veg.Length = c(142L, 137L, 153L, 159L, 174L, 
172L)), class = "data.frame", row.names = c(NA, -6L))

CODE

library(ggplot2)
ggplot(dat, aes(x = Year, y = Day.of.Green)) + geom_point() + geom_line()

OUTPUT enter image description here

If you want to add multiple columns, you can do that with more geom_point or geom_line statements which add points and lines, respectively, as the name suggests:

ggplot(dat, aes(x = Year)) + 
  geom_point(aes(y = Day.of.Green), color = 'dark red') + geom_line(aes(y = Day.of.Green), color = 'dark red') + 
  geom_point(aes(y = Day.Senesc), color = 'black') + geom_line(aes(y = Day.Senesc), color = 'black') + 
  xlab('Year') + ylab('Day of Year')

enter image description here

You can look at ggplot options to get different symbols, colors, plot types, trend-lines etc.

Gautam
  • 2,597
  • 1
  • 28
  • 51
  • The seccond plot is what I was looking for. Thanks to @Gautam – Bari Nov 21 '19 at 10:08
  • I´m wondering why there is no legend to this plot. Doesn´t ggplot2 add a legend automatically? – Bari Nov 21 '19 at 12:27
  • You can look at this question to see how you can add a legend: https://stackoverflow.com/questions/10349206/add-legend-to-ggplot2-line-plot. Alternatively, I'd also recommend `plotly` for getting interactive plots. – Gautam Nov 21 '19 at 14:44
0

This draws a line segment for each year and identifies the maximum point. (The question was not clear on which column is which so you may need to modify the column names in the code.)

library(ggplot2)

ggplot(DF, aes(Year, `Day Max`)) +
  geom_pointrange(aes(ymin = `Day of Green`, ymax = `Day Senesc`)) +
  ylab("Day")

giving

screenshot

Note

The input in reproducible form is assumed to be:

Lines <- 
"Year   \"Day of Green\"  \"Var Green\"  \"Day Max\"  \"Day Senesc\"  \"Var Senesc\"  \"Veg Length\"
2000   111           4          137      253         11          142
2001   115           5          158      252         19          137
2002   110           4          136      263         10          153
2003   112           3          143      271         16          159
2004   105           4          142      279         13          174
2005   106           5          156      278         11          172"
DF <- read.table(text = Lines, header = TRUE, check.names = FALSE)
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341