0

I have a large dataset of country's scale streamflow stations ordered as it is shown in the table. My experience in R language is beginner.

"CODE" represents streamflow stations name, and

"VAL" the streaflow value in m^3/sec.

All the timeseries for each of the stations ranges from 1/1/2002 to 31/12/2012.

Data Sample enter image description here

I'd like to plot by selecting a specific "CODE" from the whole timeseries to see in line plot format the whole timeseries and as a second step to see a monthly analysis for this station in boxplot format. No colors or other ploting effects.

/edit

What I've tried till now is the following script

library("gdata")

library("ggplot2")

timeseries <- read.csv("C:\\Users\\G\\Documents\\R\\Projects\\...\\...\\....csv", header = T)

summary(timeseries)

plot(timeseries$VAL ~ timeseries$CODE, col="light blue", pch = 19 , srt=45)

ggplot(table) + geom_point(aes(x= DATE[1:4017], y = VAL [1:4017]))

and I took a composite boxplot for all the stations for the first plot

and the ggplot didn't worked

//Final edit number after scoa solution

    library("gdata")
    library("scales")
    library("ggplot2")
    timeseries<- read.csv("C:\\Users\\G\\Documents\\R\\Projects\\...\\...\\......csv", header = T)
    timeseries$DATE <- as.Date(as.character( timeseries$DATE),format = "%d/%m/%Y")

ggplot(data= timeseries[timeseries$CODE == "StationA",]) + geom_point(aes(x= DATE, y = VAL)) + scale_x_date(breaks= date_breaks("1 month"))

Result

GeoBar
  • 37
  • 7
  • Please provide a reproducible example. Also, please post what you've tried already. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – r.bot Apr 24 '15 at 10:47

1 Answers1

1

You should subset your data.frame in data rather than aes, make sure your DATE variable is in the right format, and use scale_x_datetime().

timeseries$DATE <- as.Date(as.character(timeseries$DATE),format = "%d/%m/%Y")

library(scales)

ggplot(data=timeseries[timeseries$CODE == "a",]) + 
    geom_point(aes(x= DATE, y = VAL)) +
    scale_x_date(breaks= date_breaks("1 month"))

You may want to change the default value for date_breaks() to "3 months" or "6 months" because the axis labels are difficult to read.

scoa
  • 19,359
  • 5
  • 65
  • 80
  • This gives the time series in a "per year" format with overlapping years https://dl.dropboxusercontent.com/u/23801982/Rplot02.jpeg – GeoBar Apr 24 '15 at 12:17
  • @ scoa : "Error: Invalid input: time_trans works with objects of class POSIXct only" – GeoBar Apr 24 '15 at 12:42
  • @GeoBar then transform your date `timeseries$DATE<- as.POSIXct(timeseries$DATE)`. There is not much we can do to help you without the data – scoa Apr 24 '15 at 12:48
  • @ scoa Here is a sample https://dl.dropboxusercontent.com/u/23801982/R_forums/Sample_streamflows.csv it contains in station C some duplicates but it's not a problem – GeoBar Apr 24 '15 at 13:24
  • @ scoa Thanks a lot !!! I will update the whole code in order to be just and the question as solved – GeoBar Apr 24 '15 at 14:08