为什么没有geom_boxplot()的输出?

时间:2017-11-19 16:34:47

标签: r ggplot2 boxplot

我正在尝试为下面的数据框绘制一个方框图。运行下面的代码似乎不起作用,根本没有输出。 运行后

ggplot(aes(time, size)) +

以某种方式将数据框更改为列表。有人帮吗?

SUBJECTID   Baseline    1   2   3
1001        88          78  30  14
1002        29          26  66  16
1003        50          64  54  46
1004        91          90  99  43
1005        98          109 60  42
1007        100         100     54
1008        45          49  47  32
1009        75          66  57  7
1010        60          52  20  3
1011        68          68  56  47
1012        78          84  56  57
1013        71          70  8   5
1015        79          50  11  3
1016        73          60  57  36
1017        54          27  16
1018        50          37  33  26
1019        115         68  33  67
1021        63          55  0   0
1022        98          91  76  75
1024        76          76      0
1025        47          45  42  42
1026        32          25  14  0
1027        40          37  65  
1028        60          110 110 0

tumor.df <- clinical %>%
  select(SUBJECTID, `MRI LD Baseline`,`MRI LD 1-3dAC`,
        `MRI LD InterReg`,`MRI LD PreSurg`) %>%
  rename(baseline = 'MRI LD Baseline', t1 = 'MRI LD 1-3dAC', 
         t2 = 'MRI LD InterReg', t3 = 'MRI LD PreSurg') %>%
  gather(time, size, baseline : t3) %>%
  ggplot(aes(time, size)) +
  geom_boxplot()

1 个答案:

答案 0 :(得分:2)

这是我从以下代码获得的输出:

clinical <- read.table(text="
SUBJECTID   baseline    t1  t2  t3
1001        88          78  30  14
1002        29          26  66  16
1003        50          64  54  46
1004        91          90  99  43
1005        98          109 60  42
1007        100         100 NA  54
1008        45          49  47  32
1009        75          66  57  7
1010        60          52  20  3
1011        68          68  56  47
1012        78          84  56  57
1013        71          70  8   5
1015        79          50  11  3
1016        73          60  57  36
1017        54          27  16  NA
1018        50          37  33  26
1019        115         68  33  67
1021        63          55  0   0
1022        98          91  76  75
1024        76          76  NA    0
1025        47          45  42  42
1026        32          25  14  0
1027        40          37  65  NA
1028        60          110 110 0
", header=T)

library(ggplot2)
library(tidyr)
library(plyr)

clinical %>%
  rename(c(baseline = 'MRI LD Baseline', t1 = 'MRI LD 1-3dAC', 
         t2 = 'MRI LD InterReg', t3 = 'MRI LD PreSurg')) %>%
  gather(time, size, 'MRI LD Baseline':'MRI LD PreSurg')  %>%
  mutate(time  = factor(time, levels=unique(time)))  %>%
  ggplot(aes(time, size)) +
  geom_boxplot()

enter image description here