如何使用ggplot2生成此图形

时间:2013-04-23 07:22:16

标签: r ggplot2

这是绘制数据框时R所呈现的基本图形。

plot(df)

显示所有变量之间的关系。

the plot

我知道ggplot2中的分面,但它根据特定变量用于分区。我想通过目标参数(对于颜色)进行分面,并通过变量分割网格。

示例数据:

prediction.date  mean.forcast   mean.Error    standard.Deviation    AIC         param.u param.v
2012-08-29       0.0015608102   0.008296402   0.008296402           -6.165365   2       5
2012-08-30      -0.0002720289   0.008537309   0.008537309           -6.164167   2       4
2012-09-02      -0.0014277972   0.008194409   0.008194409           -6.168868   4       0
2012-09-03       0.0016537998   0.008062687   0.008062687           -6.176634   5       3
2012-09-04      -0.0030247699   0.007885009   0.007885009           -6.181844   4       3
2012-09-05       0.0001538991   0.007524703   0.007524703           -6.197240   3       4

1 个答案:

答案 0 :(得分:2)

如果你只需要在你提供的图中着色点,那么你可以在col=中使用参数plot()并设置颜色和变量的名称以用于确定颜色。

#variable of test result (should be the same length as number of rows in df)
test.result<-c(0,1,1,0,0,1)

plot(df[,3:7],col=c("green","red")[as.factor(test.result)])

enter image description here

相关问题