【问题标题】:R: Plotting 2 Matrices in one plotR:在一个图中绘制 2 个矩阵
【发布时间】:2014-10-09 21:41:38
【问题描述】:

我有 2 个矩阵如下:

M1:

FY1301    FY1302   FY1303  FY1304   FY1305  FY1306
 146       56       159     129       54     535
 137      113       337     140      160     777
 281      111       331     198      231     875
 273       55       480     205      356     887

M2:

FY1301    FY1302   FY1303  FY1304   FY1305  FY1306
 34        5        99       82      121    180
 89       98       252       33      311    310
101       77       252       45      284    265
170       64       125       33      187    288

我正在尝试在同一个图上绘制两个矩阵。

我目前正在做的是给我 2 个不同的情节。以下是代码:

par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
matplot(M1, type = c("b"), pch = 1, col=1:6, xlab = "Month", ylab = "Total Sessions With Med1")
legend("topright", legend = c("FY13 01","FY13 02","FY13 03","FY13 04","FY13 05","FY13 06"), inset=c(-0.11,0), col=1:6, pch=1, cex = 0.5, bty = "n")

par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
matplot(M2, type = c("b"), pch = 1, col=1:6, xlab = "Month", ylab = "Total Sessions Without Med1")
legend("topright", legend = c("FY13 01","FY13 02","FY13 03","FY13 04","FY13 05","FY13 06"), inset=c(-0.11,0), col=1:6, pch=1, cex = 0.5, bty = "n")

由于我要比较这两个图,因此我希望将两个矩阵都绘制在一个图中。 (矩阵 M1 和 M2 是我的代码的输出)

我需要对当前代码进行哪些修改?

非常感谢!!!

【问题讨论】:

    标签: r plot visualization


    【解决方案1】:

    试试:

    par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
    
    matplot(M1, type = c("b"), pch = 1, col=1:6, xlab = "Month", ylab = "Total Sessions With Med1")
        legend("topright", legend = c("FY13 01","FY13 02","FY13 03","FY13 04","FY13 05","FY13 06"), inset=c(-0.11,0), col=1:6, pch=1, cex = 0.5, bty = "n")
    
    par(new = TRUE)
    
    matplot(M2, type = c("b"), pch = 1, col=1:6, xlab = "Month", ylab = "Total Sessions Without Med1")
        legend("topright", legend = c("FY13 01","FY13 02","FY13 03","FY13 04","FY13 05","FY13 06"), inset=c(-0.11,0), col=1:6, pch=1, cex = 0.5, bty = "n")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-27
      • 2021-12-12
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多