1
votes

Im just beginning to learn R so this might be redundant so I apologize. I am wanting to make this attach excel graph in R. My data includes daily water level reading for a reservoir from 1951 to 2016. I need the data broken into three series (1951 to 2013, 2014 to 2015, and 2016). I would like to plot the median values for these series per calendar day. And I would like to remove febuary 29 from the median values. Here is a link to my data:https://docs.google.com/spreadsheets/d/1u1Whfp6VHXkZgrC0sVn_mT9XiVxszMhqlAszjZXzM1E/edit?usp=sharing

Here is what I have so far:

LL <- read.csv("BSLL.csv")
str(LL)
LLpre <- filter(LL, year > "1952" & year <"2014") 
headtail(LLpre, n=3)
medianLLpre = ddply(LLpre, .(month, day), summarise, level = median(level),   na.rm = FALSE)
LLpost <- filter(LL, year > "2013" & year < "2016")
headtail(LLpost, n=3)
medianLLpost = ddply(LLpost, .(month, day), summarise, level = median(level), na.rm = FALSE)
LL2016 <- filter(LL, year == "2016")
headtail(LL2016, n=3)
medianLL2016 = ddply(LL2016, .(month, day), summarise, level = median(level), na.rm = FALSE)    

Excel Plot

1

1 Answers

0
votes
library(data.table)
Data <- fread("BSLL - BSLL.csv")

Create temporary time interval categories 1=1951 to 2013,2=2014 to 2015, and 3=2016

Data[,Categories:=ifelse(as.numeric(year)<2014,1,
                         ifelse(as.numeric(year)<2016,2,3))]

Create temporary data with no feb 29th

Temp.Data <- Data[!month==2][!day==29]

Compute the median by categories and plot.

Medians <- Temp.Data[,median(as.numeric(level)),by=.(month,Categories)]
plot(x=Medians[,month], y=Medians[,V1],type="n", xlab="", ylab="", 
     xaxt="n", yaxt="n", bty="l")
axis(2, tick=TRUE, labels=FALSE)
axis(2, tick=FALSE, labels=TRUE, line=-0.5)
axis(1, tick=TRUE, labels=FALSE)
axis(1, tick=FALSE, labels=TRUE, line=-0.5)
lines(x=Medians[Categories==1][,month],
      y=Medians[Categories==1][,V1],type="l",lwd=1,col="red")
lines(x=Medians[Categories==2][,month],
      y=Medians[Categories==2][,V1],type="l",lwd=1,col="green")
lines(x=Medians[Categories==3][,month],
      y=Medians[Categories==3][,V1],type="l",lwd=1,col="blue")
legend('topright','groups',
       legend=c("1951 to 2013","2014 to 2015","2016"), bty="n",lty=c(1,1),
       col=c("red","green","blue"))

How's this? You can tinker with the details of the plot (sizes, positions, colours, labels, etc.. yourself)

P.S in future its not a good idea to release your full data set publicly. Contributors here just need an example of your data to work with and test