In: Statistics and Probability
a. In R there is an built in data frame Nile. This has the annual flow in river Nile for year 1871 to 1971. Produce a time series plot. Print graph(s).
b. add the title as "Nile River Annual Flow", x axis label as "Year" and y axis label as "Flow". Print graph(s).
c. Add a horizontal line showing the average flow over these years. Print graph(s).
d. Add text as: "Average Flow:" with the calculated average flow on the chart. (hint: you can use mean function). Print graph(s).
Please add screenshot of code!
The R code for completing the above problem along with the step by step graphs is given as follows,
*********************************************************************************************************************************************
######## Calling the 'datasets' package containing dataframe
'Nile'########
library(datasets)
df <- Nile
###### Part a : Produce a time series plot ########
plot.ts(df)
###### Part b : Adding Titles and labels ########
plot.ts(df, main = "Nile River Annual
Flow",xlab="Year",ylab="Flow")
###### Part c : Adding horizontal line for average flow ########
plot.ts(df, main = "Nile River Annual
Flow",xlab="Year",ylab="Flow")
abline(h=mean(d)) ## 'h' inside 'abline()' stands for horizontal,
similarly 'v' stands for 'vertical'
###### Part d : Adding text, 'Average Flow' on the chart ########
plot.ts(d, main = "Nile River Annual
Flow",xlab="Year",ylab="Flow")
abline(h=mean(d))
temp<-locator(1) ### on executing this line, please select a
point in the plot where you want the text to be shown, then execute
next line of code
text(temp,"Average Flow")
********************************************************************************************************************************************
PLEASE UPVOTE MY ANSWER IF YOUR QUERY IS CLARIFIED.