如何在两种不同颜色的格子上绘制图形

时间:2014-12-30 19:29:20

标签: r lattice

我试图绘制以下数据

> data
  epochs      rmse learner momentum
1      1 0.2992122     0.3      0.0
2      1 0.3082895     0.1      0.2
3      1 0.2955586     0.5      0.2
4      1 0.2955182     0.3      0.4
5     11 0.2916979     0.3      0.0
6     11 0.2919140     0.1      0.2
7     11 0.2928490     0.5      0.2
8     11 0.2906339     0.3      0.4

我想要一个图表在x轴上epochs,在y轴上有rmse,并且在标记learner和{{1}时为每行绘制单独的行}。

我试着这样画:

momentum

但这是创建仅包含 > xyplot(rmse ~ epochs, data=data, groups = data$learner, type = "l", auto.key = list(space = "right", points = FALSE, lines = TRUE)) 值的图表,也没有考虑动量。

enter image description here

如何修复图表,使标签显示为:

learner

1 个答案:

答案 0 :(得分:1)

我认为您希望这些群组成为learnermomentum的互动:

xyplot(rmse ~ epochs, data=data,
       groups = interaction(learner,momentum, sep=" : ", drop=TRUE),
       type = "l",
       auto.key =
           list(space = "right", points = FALSE, lines = TRUE))

enter image description here

(请注意,我们不需要指定data$learner等,因为数据框已被拉入环境中。)

上面,interaction正在创建一个基于输入learnermomentum的因素(在将这些因素强加给因素之后),但我们可以创建我们希望用于组。特别是,我们可以使用paste创建一个用于组的向量,以及您想要的标签:

xyplot(rmse ~ epochs, data=data,
       groups = paste("L =", learner, "M =", momentum),
       type = "l",
       auto.key =
           list(space = "right", points = FALSE, lines = TRUE))

enter image description here