繁体   English   中英

使用ggplot2在R中绘制时间序列,

[英]Plotting a time series in R using ggplot2,

我尝试创建一个时间序列,其中x = yeary = cpue_wt ,按站分组。 我有7个工作站:这是1986-2011年数据的快照。 我要一个地块,用7条不同的线,每条线代表一个时间站。

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

这是我要使用的代码:

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"))

这是我的错误:

Continuous value supplied to discrete scale

我假设我的数据没有正确组织。

任何帮助将不胜感激。

由于station值是数字,并且要为每行设置特定的颜色,因此应将as.factor(station)添加到colour=以将数值转换为系数。

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"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM