简体   繁体   中英

Why no output for geom_boxplot()?

I am trying to plot a box plot for the data frame below. Running the code below seems doesn't work, there is no output at all. After running

ggplot(aes(time, size)) +

somehow the dataframe was changed to a list. Anyone helps?

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()

This is the output I get from the following code:

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()

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM