如何在R

时间:2019-08-22 14:25:34

标签: r boxplot

I used this code to produce a boxplot:
x1 <- rnorm(500)
y1 <- sample(c("a", "b", "c"), 500, replace=T)
boxplot(x1 ~ y1)

我想在图表中添加一张表格,但是我不确定我可以用来执行此操作的代码:

   A  B
1 26 63
2 64 64
3 54 26
4 98 82
5 95  3
> dput(temp)
structure(list(A = c(26, 64, 54, 98, 95), B = c(63, 64, 26, 82, 
3)), .Names = c("A", "B"), class = "data.frame", row.names = c(NA, 
5L))

是执行此操作的函数,因为我在箱线图文档中没有看到它?

1 个答案:

答案 0 :(得分:0)

这是使用base R的手动解决方案。

  x1 <- rnorm(500)
  y1 <- sample(c("a", "b", "c"), 500, replace=T)

par(mar=c(4,4,4,6),xpd=TRUE)
boxplot(x1 ~ y1)

legend('topright',inset=c(-0.275,0),
c("     A  B",
  "1 26 63",
  "2 64 64",
  "3 54 26",
  "4 98 82",
  "5 95  3")) 

enter image description here