如何在R中绘制以下功能?

时间:2014-09-17 03:42:49

标签: r plot

我有以下表格的数据:

Team win%JAN win%FEB win%MARCH win%APRIL
X      23        45     34       56 
Y      34         56     25      29
Z      47         37     26      39

等等。如何为每个团队绘制一个曲线(线),每个团队对应几个月的胜利百分比,以便我可以预测每个团队下个月的胜利百分比?

1 个答案:

答案 0 :(得分:1)

尝试:

ddf = structure(list(Team = structure(1:3, .Label = c("X", "Y", "Z"
+ ), class = "factor"), win.JAN = c(23L, 34L, 47L), win.FEB = c(45L, 
+ 56L, 37L), win.MARCH = c(34L, 25L, 26L), win.APRIL = c(56L, 29L, 
+ 39L)), .Names = c("Team", "win.JAN", "win.FEB", "win.MARCH", 
+ "win.APRIL"), class = "data.frame", row.names = c(NA, -3L))
> 
> 
> ddf
  Team win.JAN win.FEB win.MARCH win.APRIL
1    X      23      45        34        56
2    Y      34      56        25        29
3    Z      47      37        26        39
> 
> library(reshape2)
> mm = melt(ddf)
> library(ggplot2)
 ggplot(mm, aes(x=variable, y=value, group=Team, color=Team))+geom_point()+geom_line()

enter image description here