在表格旁边显示条形图 - R.

时间:2016-11-23 12:24:19

标签: r

我试图找到一种方法来显示条形图和它们是为了报告目的而并排生成的数据框。例如,我有以下数据框:

> green
   Player.Name  Tm at Opp W/L    MP FG FGA x3P x3PA FT FTA ORB DRB TRB AST STL BLK TOV PF PTS USG. Line   MB    DS     Date
Draymond Green GSW    SAS   L 32:37  7  14   2    5  2   2   5   7  12   6   5   1   2  2  18 22.8   29 51.4 55.25 20161025
Draymond Green GSW  @ NOP   W 34:04  3  10   1    2  1   2   4   7  11   7   2   0   3  5   8 16.7   -8 32.7 33.75 20161028
Draymond Green GSW  @ PHO   W 37:47  2   9   0    4  1   2   1  12  13   9   0   3   2  3   5 13.4   -6 38.1 37.75 20161030
Draymond Green GSW  @ POR   W 30:01  2   3   1    2  1   2   0   8   8   9   3   2   0  2   6  5.4  -23 39.1 40.00 20161101
Draymond Green GSW    OKC   W 29:10  2   9   0    2  5   6   4   6  10   5   1   4   4  3   9 22.6  -26 34.5 35.00 20161103
Draymond Green GSW  @ LAL   L 33:41  6  10   0    3  4   6   2   7   9   4   4   0   1  1  16 16.9   20 39.8 39.25 20161104
Draymond Green GSW    NOP   W 34:42  2   7   0    1  0   0   2  10  12  11   2   2   2  3   4 11.3  -10 40.9 43.25 20161107
Draymond Green GSW    DAL   W 34:36  6  11   4    6  0   1   1   9  10   4   0   2   1  3  16 17.5  -21 37.0 42.50 20161109
Draymond Green GSW  @ DEN   W 28:46  4   7   3    4  2   2   0   9   9   5   3   0   1  2  13 13.6  -24 36.3 39.50 20161110
Draymond Green GSW    PHO   W 37:01  4  10   1    5  5   5   2   5   7  11   3   2   3  3  14 16.9  -13 45.9 49.25 20161113
Draymond Green GSW  @ TOR   W 34:54  5  13   1    4  0   0   0   7   7   5   2   3   3  4  11 19.8   -6 33.9 34.75 20161116
Draymond Green GSW  @ BOS   W 35:09  3  11   2    6  3   4   1   7   8   8   1   1   1  3  11 17.7  -16 35.6 36.25 20161118
Draymond Green GSW  @ MIL   W 35:31  3   7   0    1  4   4   1   1   2   5   3   2   2  3  10 12.0   -3 27.9 28.00 20161119
Draymond Green GSW  @ IND   W 29:25  4   7   0    2  2   2   3   6   9   7   2   2   1  1  10 12.5  -37 38.3 38.50 20161121

从此我用:

创建了条形图
barplot(green$MB,names.arg=green$Date,las=2,main="Draymond Green MB Fantasy Points")

Draymond Green MB Fantasy Points

barplot(green$DS,names.arg=green$Date,las=2,main="Draymond Green DS Fantasy Points")

Draymond Green DS Fantasy Points

我希望能够创建如下输出。条形图垂直对齐,数据框右对齐(最好是垂直居中但不是必需的)。

Combined Barplots and Table

2 个答案:

答案 0 :(得分:0)

您可以将layout()功能与gplots包一起使用。例:

library(gplots)

layout(matrix(c(1, 2, 3, 3), nrow = 2))
hist(rnorm(100))
hist(rnorm(50))
textplot(head(iris))

enter image description here

答案 1 :(得分:0)

使用ggplot2:

green$Date <- as.factor(green$Date)
library(gridExtra)
library(grid)
grid.arrange(
  ggplot(green, aes(Date, MB)) + geom_bar(stat='identity') + theme(axis.text.x = element_text(angle=90, vjust = 0.5)) + ggtitle('Draymond Green MB Fantasy Points'),
  ggplot(green, aes(Date, DS)) + geom_bar(stat='identity') + theme(axis.text.x = element_text(angle=90, vjust = 0.5)) + ggtitle('Draymond Green DS Fantasy Points'),
  tableGrob(green), ncol=4, layout_matrix = rbind(c(1,3,3,3),c(2,3,3,3)))

enter image description here