r - Side by side plots but y scales not aligned even though the same -


i'd appreciate problem.

i plotting 2 charts side side. both have same y scale not aligned (50 higher in 1 plot other 150 @ same level). how can rectify this?

require(cowplot)     p3 = ggplot(ecghr_merged) +geom_line(aes(x = time, y=ecg_hr_ch, group=id), alpha=0.2) +       geom_hline( aes(yintercept = 70.66), color="blue") +       scale_y_continuous(limits=c(20,190)) +       ggtitle("ecg hr: challenge day") + xlab("time before reaction (mins)") +       ylab("ecg hr (bpm)")    p4 = ggplot(ecghr_merged) +geom_line(aes(x = time, y=ecg_hr_pl, group=id), alpha=0.2)+   geom_hline( aes(yintercept = 67.09), color="blue") +   ggtitle("ecg hr: placebo day") + xlab("time before reaction (mins.)")+   ylab("ecg hr (bpm)")    plot_grid(p4, p3) 

enter image description here

example data:

print(ecghr_merged)            id time  t.x ecg_hr_ch  t.y ecg_hr_pl 1    2003    0   t0        70   t0        57 2    2003    1   t1        65   t1        66 44   2003    2   t2        69   t2        56 55   2003    3   t3        71   t3        62 66   2003    4   t4        68   t4        59 77   2003    5   t5        74   t5        58 88   2003    6   t6        67   t6        71 99   2003    7   t7        65   t7        68 110  2003    8   t8        60   t8        66 121  2003    9   t9        66   t9        61 3    2003   10  t10        59  t10        61 14   2003   11  t11        99  t11        59 25   2003   12  t12        74  t12        59 36   2003   13  t13        73  t13        62 38   2003   14  t14        87  t14        62 39   2003   15  t15        94  t15        65 40   2003   16  t16        88  t16        65 41   2003   17  t17        88  t17        67 42   2003   18  t18        98  t18        63 43   2003   19  t19        73  t19        64 45   2003   20  t20        72  t20        65 46   2003   21  t21        63  t21        63 47   2003   22  t22        79  t22        58 48   2003   23  t23        63  t23        65 49   2003   24  t24        62  t24        60 50   2003   25  t25        66  t25        70 51   2003   26  t26        57  t26        63 52   2003   27  t27        64  t27        65 53   2003   28  t28        70  t28        61 54   2003   29  t29        65  t29        64 56   2003   30  t30        78  t30        59 57   2003   31  t31        59  t31        73 58   2003   32  t32        64  t32        71 59   2003   33  t33        69  t33        66 60   2003   34  t34        60  t34        54 61   2003   35  t35        55  t35        59 62   2003   36  t36        61  t36        55 63   2003   37  t37        70  t37        59 64   2003   38  t38        71  t38        61 65   2003   39  t39        64  t39        58 67   2003   40  t40        56  t40        64 68   2003   41  t41        68  t41        60 69   2003   42  t42        64  t42        62 70   2003   43  t43        63  t43        65 71   2003   44  t44        65  t44        58 72   2003   45  t45        67  t45        64 73   2003   46  t46        59  t46        64 74   2003   47  t47        58  t47        60 75   2003   48  t48        60  t48        60 76   2003   49  t49        61  t49        66 78   2003   50  t50        63  t50        58 79   2003   51  t51        65  t51        63 80   2003   52  t52        67  t52        56 81   2003   53  t53        60  t53        61 82   2003   54  t54        67  t54        57 83   2003   55  t55        62  t55        54 84   2003   56  t56        64  t56        59 85   2003   57  t57        60  t57        61 86   2003   58  t58        58  t58        57 87   2003   59  t59        64  t59        61 89   2003   60  t60        65  t60        65 90   2003   61  t61        64  t61        63 91   2003   62  t62        63  t62        60 92   2003   63  t63        63  t63        56 93   2003   64  t64        63  t64        58 94   2003   65  t65        69  t65        57 95   2003   66  t66        63  t66        64 96   2003   67  t67        62  t67        59 97   2003   68  t68        71  t68        59 98   2003   69  t69        61  t69        57 100  2003   70  t70        68  t70        55 101  2003   71  t71        63  t71        60 102  2003   72  t72        68  t72        56 103  2003   73  t73        60  t73        58 104  2003   74  t74        60  t74        65 105  2003   75  t75        61  t75        58 106  2003   76  t76        65  t76        60 107  2003   77  t77        59  t77        60 108  2003   78  t78        66  t78        66 109  2003   79  t79        61  t79        60 111  2003   80  t80        58  t80        62 112  2003   81  t81        59  t81        63 113  2003   82  t82        57  t82        59 114  2003   83  t83        59  t83        58 115  2003   84  t84        60  t84        61 116  2003   85  t85        58  t85        57 117  2003   86  t86        63  t86        65 118  2003   87  t87        64  t87        64 119  2003   88  t88        61  t88        63 120  2003   89  t89        58  t89        64 122  2003   90  t90        65  t90        61 123  2003   91  t91        60  t91        56 124  2003   92  t92        63  t92        60 125  2003   93  t93        55  t93        62 126  2003   94  t94        57  t94        59 127  2003   95  t95        61  t95        59 128  2003   96  t96        57  t96        56 129  2003   97  t97        72  t97        59 130  2003   98  t98        55  t98        62 131  2003   99  t99        73  t99        56 4    2003  100 t100        56 t100        85 5    2003  101 t101        59 t101        56 6    2003  102 t102        61 t102        55 7    2003  103 t103        63 t103        55 8    2003  104 t104        57 t104        59 9    2003  105 t105        60 t105        61 10   2003  106 t106        61 t106        55 11   2003  107 t107        56 t107        57 12   2003  108 t108        62 t108        57 13   2003  109 t109        60 t109        65 15   2003  110 t110        63 t110        55 16   2003  111 t111        60 t111        57 17   2003  112 t112        57 t112        55 18   2003  113 t113        69 t113        79 19   2003  114 t114        65 t114        59 20   2003  115 t115        60 t115        59 21   2003  116 t116        61 t116        58 22   2003  117 t117        62 t117        61 23   2003  118 t118        65 t118        61 24   2003  119 t119        59 t119        63 26   2003  120 t120        60 t120        68 27   2003  121 t121        60 t121        60 28   2003  122 t122        72 t122        61 29   2003  123 t123        67 t123        62 30   2003  124 t124        63 t124        65 31   2003  125 t125        59 t125        64 32   2003  126 t126        62 t126        58 33   2003  127 t127        58 t127        61 34   2003  128 t128        64 t128        58 35   2003  129 t129        60 t129        58 37   2003  130 t130        68 t130        60 132  2004    0   t0        98   t0        77 133  2004    1   t1       105   t1        82 175  2004    2   t2        85   t2        69 186  2004    3   t3        87   t3        88 197  2004    4   t4        83   t4       100 208  2004    5   t5        83   t5        91 219  2004    6   t6        77   t6        72 230  2004    7   t7        71   t7        79 241  2004    8   t8        75   t8        65 252  2004    9   t9        73   t9        73 134  2004   10  t10        73  t10        69 145  2004   11  t11        71  t11        65 156  2004   12  t12        87  t12        63 167  2004   13  t13        74  t13        62 169  2004   14  t14        79  t14        64 170  2004   15  t15        75  t15        63 171  2004   16  t16        72  t16        64 172  2004   17  t17        71  t17        67 173  2004   18  t18        71  t18        69 174  2004   19  t19        68  t19        66 176  2004   20  t20        86  t20        65 177  2004   21  t21        72  t21        64 178  2004   22  t22        73  t22        69 179  2004   23  t23        69  t23        67 180  2004   24  t24        75  t24        66 181  2004   25  t25        73  t25        68 182  2004   26  t26        70  t26        68 183  2004   27  t27        76  t27        67 184  2004   28  t28        71  t28        64 185  2004   29  t29        68  t29        69 187  2004   30  t30        68  t30        67 188  2004   31  t31        76  t31        65 189  2004   32  t32        69  t32        65 190  2004   33  t33        73  t33        66 191  2004   34  t34        74  t34        64 

you set scale_y_continuous(limits=c(20,190)) in p3, not in p4.

this means limits in p4 calculated data inside it.

require(cowplot)  p3 <- ggplot(ecghr_merged) +     geom_line(aes(x = time, y = ecg_hr_ch, group = id), alpha = 0.2) +     geom_hline(aes(yintercept = 70.66), color = "blue") +     scale_y_continuous(limits = c(20,190)) +     ggtitle("ecg hr: challenge day") +      xlab("time before reaction (mins)") +     ylab("ecg hr (bpm)")  p4 <- ggplot(ecghr_merged) +     geom_line(aes(x = time, y = ecg_hr_pl, group = id), alpha=0.2)+     geom_hline(aes(yintercept = 67.09), color = "blue") +     scale_y_continuous(limits = c(20,190)) +     ggtitle("ecg hr: placebo day") +      xlab("time before reaction (mins.)")+     ylab("ecg hr (bpm)")   plot_grid(p4, p3) 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -