首页 > 解决方案 > 在 R 中自动绘制 x 个图形

问题描述

我想生成一个函数来自动绘制 x 个数字(没有 ggplot),我的图如下(它们没有达到我的预期,它们太大并且不适合 par 函数的行或列):

chess_games<-read.csv("./data/games.csv")
chess_games_rated<-table(chess_games$rated)
head (chess_games_rated)
bp.1<-barplot(chess_games_rated, cex.lab=1.5, cex.axis=1.2, font=1)


chess_games<-read.csv("./data/games.csv")
chess_games_rated<-table(chess_games$winner, chess_games$rated)
bp.3<-barplot(chess_games_rated, col=c("blue","red","green"), cex.axis=1.5)
bp.4<-legend(x="topleft", legend = levels(df.1$winner), col=c("blue","red","green"), pch=19, cex=1, pt.cex = 1)
bp.2<-c(bp.3, bp.4)

boxplot.1<-boxplot(cream_rating ~ victory_status, chess_games[!chess_games$winner %in% "draw", ], cex.axis=1.2)
par(mai=rep(0.5, 4))
layout(matrix(c(1,1, 2,2, 0, 3,3, 0), ncol = 4, byrow = TRUE))
bp.1
bp.2
boxplot.1

我的数据是:

A data.frame: 6 × 8
    rated   turns   victory_status  winner  increment_code  cream_rating    charcoal_rating   opening_name
    <lgl>   <int>   <fct>          <fct>    <fct>            <int>          <int>              <fct>
1   FALSE   13     outoftime       cream    15+2             1500           1191              Slav Defense: Exchange Variation
2   TRUE    16      resign        charcoal  5+10             1322           1261              Nimzowitsch Defense: Kennedy Variation
3   TRUE    61      mate           cream    5+10             1496           1500              King's Pawn Game: Leonardis Variation
4   TRUE    61      mate           cream    20+0            1439            1454              Queen's Pawn Game: Zukertort Variation
5   TRUE    95      mate           cream    30+3            1523            1469              Philidor Defense
6   FALSE   5       draw            draw    10+0            1250            1002     

我试过这个:

rowplot<-function(x,y,z) {par(mfrow=c(1,3)) (layout(matrix(c(1,1, 2,2, 0, 3,3, 0), ncol = 4, byrow = TRUE)))}
rowplot(bp.1,bp.2,boxplot.1)

但它什么也不返回。

标签: r

解决方案


推荐阅读