Wednesday, 15 September 2010

Plotting a time series in R using ggplot2, -



Plotting a time series in R using ggplot2, -

i'm seek create time series where, x = year, y = cpue_wt, grouped station. have 7 stations: here snapshot of data, goes 1986-2011. want 1 plot, 7 different lines, each represents 1 station through time.

year station cpue_wt 1986 531 3.400346954 1986 537 1.292539282 1986 538 1.097930493 1986 541 1.220753481 1986 550 1.350880331 1986 552 1.168257879 1986 555 2.012733899 1987 531 1.817902609 1987 537 2.024999967 1987 538 1.563596954

here code i'm trying use:

sst <- ggplot(yrsta, aes(group = factor(station), x = year, y = cpue_wt, colour = station)) + geom_line() + scale_color_manual(values=c("#999999", "#e69f00", "#56b4e9", "#009e73", "#f0e442", "#0072b2", "#d55e00"))

here error:

continuous value supplied discrete scale

i'm assuming info not organized correctly.

any help appreciated.

as station values numeric , want set particular color each line, should add together as.factor(station) colour= convert numerical values factor.

ggplot(yrsta, aes(group = factor(station), x = year, y = cpue_wt, colour = as.factor(station))) + geom_line() + scale_color_manual(values=c("#999999", "#e69f00", "#56b4e9", "#009e73", "#f0e442", "#0072b2", "#d55e00"))

r ggplot2 time-series

No comments:

Post a Comment