I'm trying to plot the following data
我正在尝试绘制以下数据
> 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
I want a graph that has epochs
on x-axis, rmse
on y-axist, and graphs a separate line for each row while labeling the learner
and momentum
.
我想要一个在x轴上具有历元的图形,在y轴上具有rmse,并且在标记学习者和动量时为每行绘制单独的线。
I tried plot it like this:
我尝试这样绘制它:
> xyplot(rmse ~ epochs, data=data, groups = data$learner,
type = "l",
auto.key =
list(space = "right", points = FALSE, lines = TRUE))
but this is creating graph with only learner
values, it is not taking into account the momentum as well.
但这是创建只有学习者价值的图表,也没有考虑到动量。
How can I fix the graph such that the labels read:
如何修复图形,使标签显示为:
L = 0.1, M=0.2 <somecolor>
L = 0.3, M=0.0 <somecolor>
L = 0.5, M=0.2 <somecolor>
L = 0.3, M=0.4 <somecolor>
1 个解决方案
#1
1
I think you want the groups to be the interaction of learner
and momentum
:
我想你希望这些小组成为学习者和动力的互动:
xyplot(rmse ~ epochs, data=data,
groups = interaction(learner,momentum, sep=" : ", drop=TRUE),
type = "l",
auto.key =
list(space = "right", points = FALSE, lines = TRUE))
(Note that we don't need to specify data$learner
, etc, as the data frame is pulled into the environment.)
(注意,我们不需要指定数据$ learner等,因为数据框被拉入环境中。)
Above, interaction
is creating a factor based on the inputs learner
and momentum
(after coercing these to factors), but we can create any factor that we desire to use for the groups. In particular, we can use paste
to create a vector to use for the groups, with the labels that you want:
在上文中,交互是基于输入学习者和动量(在将这些因素强加到因子之后)创建一个因素,但我们可以创建我们希望用于组的任何因子。特别是,我们可以使用粘贴来创建一个用于组的向量,以及您想要的标签:
xyplot(rmse ~ epochs, data=data,
groups = paste("L =", learner, "M =", momentum),
type = "l",
auto.key =
list(space = "right", points = FALSE, lines = TRUE))
#1
1
I think you want the groups to be the interaction of learner
and momentum
:
我想你希望这些小组成为学习者和动力的互动:
xyplot(rmse ~ epochs, data=data,
groups = interaction(learner,momentum, sep=" : ", drop=TRUE),
type = "l",
auto.key =
list(space = "right", points = FALSE, lines = TRUE))
(Note that we don't need to specify data$learner
, etc, as the data frame is pulled into the environment.)
(注意,我们不需要指定数据$ learner等,因为数据框被拉入环境中。)
Above, interaction
is creating a factor based on the inputs learner
and momentum
(after coercing these to factors), but we can create any factor that we desire to use for the groups. In particular, we can use paste
to create a vector to use for the groups, with the labels that you want:
在上文中,交互是基于输入学习者和动量(在将这些因素强加到因子之后)创建一个因素,但我们可以创建我们希望用于组的任何因子。特别是,我们可以使用粘贴来创建一个用于组的向量,以及您想要的标签:
xyplot(rmse ~ epochs, data=data,
groups = paste("L =", learner, "M =", momentum),
type = "l",
auto.key =
list(space = "right", points = FALSE, lines = TRUE))