putting segments on a plot with multiple plots and y variables - r

Is there a way to put arrows on a plot with multiple plots with different y axes? I would like to put arrows across the time series on the same x axis locations but different y locations. I cant just use "annotate("segment", x = 37, xend = 84, y = 0.0, yend = 0.0,colour = "black", size = 1, arrow = arrow(ends='both'))" because then it puts them at 0 on the y axis for all variables when I actually want to just put the arrows at the bottom of the y axis which is different for every variable.
Current code:
fin_plot <- ggplot(melted_data, aes(x = `Distance`, y = value, group = variable)) + geom_line() + theme_bw() + labs(y="", x= "") + theme_classic() + theme(text=element_text(size=16, family="serif", face = "bold", color = "black")) +
facet_wrap(variable~., scales = "free_y",ncol=2) +
scale_x_continuous(limits = c(0, 250),labels = scales::number_format(accuracy = 1)) + theme(axis.line = element_line(colour = 'black', size = 1)) +
theme(axis.ticks = element_line(colour = "black", size = 1)) + scale_y_continuous(labels = scales::number_format(accuracy = 0.1))+ theme(axis.ticks.length = unit(.3, "cm")) + coord_capped_cart(bottom='right', left='none', gap = 0.15) + geom_vline(xintercept=c(58, 132, 204, 250, 309), linetype='dashed', col = 'black')
Current output
desired output
data:
melted_data <- structure(list(Distance = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149), variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L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, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L), .Label = c("Mg", "Mn", "Zn", "Ba", "All"), class = "factor"),
value = c(0.903247645, 0.912560748, 0.896003508, 0.909572697,
0.883631829, 0.905722594, 0.892465355, 0.909271173, 0.880506202,
0.889278401, 0.878534542, 0.959209459, 0.913303825, 0.929893977,
0.97778374, 0.9885554, 0.929716333, 1.028422583, 1.025638955,
1.011352651, 1.041343955, 1.092562951, 1.129761801, 1.088857171,
1.107257284, 1.116728405, 1.103053734, 1.041662037, 1.134182243,
1.104550315, 1.086952767, 1.106004784, 1.057688595, 1.034347579,
1.04641385, 1.139270945, 1.048446018, 1.033827731, 1.075554754,
1.029893202, 1.074749532, 1.001626205, 0.977053541, 0.987467665,
0.999540478, 0.945184816, 0.959677178, 0.962807712, 0.967023936,
1.024286493, 0.881264816, 0.967181342, 1.000316876, 0.956168258,
1.003214572, 1.00047837, 0.940103474, 0.929875987, 0.928227112,
0.982410241, 0.983035162, 0.976666772, 1.019755049, 1.075189042,
0.975380543, 0.981316782, 0.986876269, 1.026690916, 1.052379934,
1.001547298, 0.979888683, 1.008209647, 0.976098272, 0.944479556,
0.996767684, 1.018077758, 1.028862706, 1.08510417, 1.08963868,
1.048481179, 1.139954126, 1.107066353, 1.122920581, 1.23904326,
1.19449336, 1.179971969, 1.165865352, 1.068804094, 1.099436469,
1.073307737, 1.07045113, 1.101007051, 1.011962649, 1.11202545,
1.097883672, 1.05361424, 0.993283703, 1.046635444, 1.04951188,
1.055736151, 1.063705172, 0.977095039, 1.015650848, 1.029367222,
1.003814349, 0.973376993, 1.021665177, 0.925511352, 1.014703757,
0.933654542, 1.027336075, 0.961163947, 1.022921765, 0.910164297,
0.937410814, 0.935246588, 0.925900983, 0.934477753, 0.927973832,
0.946372309, 0.950554394, 0.9386026, 1.000712639, 0.947846812,
0.953585987, 0.967735737, 0.927914753, 0.943303715, 0.935435884,
0.987648375, 0.902379461, 0.939086878, 1.018529942, 0.973874968,
0.974093087, 0.984149676, 0.948669001, 0.934863295, 1.011232041,
0.942884239, 0.978044788, 1.023700208, 1.011714275, 0.999153709,
1.06822476, 0.967735328, 1.131133479, 1.011068503, 1.034903609,
0.086720869, 0.113119382, 0.088197332, 0.081547788, 0.079373211,
0.07888827, 0.072865285, 0.079637996, 0.066314774, 0.097585729,
0.185034982, 0.214466904, 0.294317625, 0.481389256, 0.531196058,
0.715842439, 0.865098887, 0.987242052, 1.081028291, 1.240920518,
1.313524957, 1.543771699, 1.78495042, 1.746572555, 2.048760527,
2.101438775, 1.967474033, 2.000286925, 2.014020838, 1.924470659,
1.75696549, 1.786681246, 1.633290961, 1.455799758, 1.315346538,
1.435348984, 1.27887702, 1.152818928, 1.095127218, 0.987502349,
1.062278922, 0.898540082, 0.83617998, 0.889057689, 0.825563648,
0.788347646, 0.790973555, 0.775541228, 0.815063004, 0.848723108,
0.66783059, 0.672629631, 0.747809615, 0.72338158, 0.666220438,
0.664051795, 0.597260657, 0.689282162, 0.663808452, 0.678551141,
0.672917354, 0.686199986, 0.724202364, 0.746195474, 0.686135659,
0.654148537, 0.713488795, 0.72446665, 0.699529989, 0.630120423,
0.661767463, 0.663290351, 0.705879842, 0.709399338, 0.76228353,
0.714368918, 0.720561695, 0.837036666, 0.923882149, 1.014163852,
1.221410703, 1.315825246, 1.368054705, 1.641746627, 1.630198312,
1.698589629, 1.562956393, 1.427322658, 1.53964983, 1.574583495,
1.527101216, 1.380123116, 1.28649445, 1.29251968, 1.330565441,
1.317758525, 1.19292313, 1.217953538, 1.218591815, 1.163372928,
1.091026791, 0.878691182, 0.903966928, 0.917620557, 0.838430901,
0.825709255, 0.839298558, 0.76309434, 0.97617394, 0.739885015,
0.822159341, 0.785335779, 0.771926988, 0.766619321, 0.832448556,
0.733734124, 0.787221188, 0.685452005, 0.740552711, 0.707414697,
0.781271754, 0.72652958, 0.729470139, 0.71649368, 0.681176551,
0.683977986, 0.711079301, 0.681092777, 0.747615639, 0.700953146,
0.692246657, 0.673560118, 0.820384633, 0.740567172, 0.72070082,
0.795192662, 0.773897168, 0.74552279, 0.735710787, 0.768825863,
0.746016457, 0.736542042, 0.744507532, 0.784312542, 0.758393534,
0.7600356, 0.797384742, 0.773626898, 0.744557896, 0.746612627,
0.818368055, 0.696689824, 0.748702805, 0.717457681, 0.766243608,
0.805305259, 0.855909762, 0.803357905, 0.889646097, 0.854456208,
1.067795473, 1.051422575, 1.17061972, 1.138440648, 1.052796919,
1.040998633, 1.161739158, 1.025956799, 0.971567748, 1.072911493,
0.952121155, 1.040392714, 1.069745522, 1.068549198, 1.090194087,
1.214584829, 1.157485471, 1.245813376, 1.336359991, 1.204038397,
1.126255292, 1.131057736, 0.922042386, 1.037566449, 1.100852394,
1.121842367, 0.998657748, 1.006938923, 1.002800377, 0.897387497,
0.93902937, 0.889327622, 0.802133735, 0.855245047, 0.860702407,
0.704324249, 0.905827093, 0.760155095, 0.760247698, 0.655991619,
0.677006743, 0.668001976, 0.623410532, 0.569302474, 0.523713794,
0.690042836, 0.539115342, 0.528696218, 0.57851915, 0.60294784,
0.581392042, 0.65277069, 0.65620614, 0.625397246, 0.697647782,
0.6180657, 0.632326126, 0.684659215, 0.606197513, 0.630134281,
0.637151517, 0.574538208, 0.605993607, 0.533522181, 0.544522236,
0.577535469, 0.573427383, 0.672984155, 0.735286828, 0.7532343,
0.881292245, 0.801132661, 1.122761046, 1.137397845, 1.173190388,
1.138033979, 1.126494557, 1.144871399, 1.087042815, 0.981750792,
0.992888445, 0.955352455, 1.074357698, 1.027127808, 1.083248059,
1.010304962, 1.037776316, 1.052809984, 0.959161909, 0.939369893,
0.932304641, 0.912110856, 1.035278327, 0.825391661, 0.883818816,
0.880397247, 0.775385156, 0.860535004, 0.75878312, 0.764243502,
0.788209749, 0.736029937, 0.746966542, 0.762295984, 0.804665042,
0.797845669, 0.744225613, 0.846139103, 0.806957411, 0.789078125,
0.912631032, 0.926629248, 0.807376002, 0.795165332, 0.776764645,
0.811532921, 0.740169463, 0.707007363, 0.764252403, 0.754265833,
0.656183602, 0.78602999, 0.734580057, 0.756587437, 0.750509131,
0.727536118, 0.676232276, 0.714439923, 0.720668076, 0.763533465,
0.60234143, 0.651920197, 0.744086872, 0.633919728, 0.615213712,
0.705944962, 0.667362984, 0.742636421, 0.742734852, 0.839492568,
0.743899849, 0.817080816, 0.773569657, 0.735728339, 0.715168283,
0.78077814, 0.694280484, 0.773303425, 0.768041196, 0.883401699,
0.818274274, 0.715927964, 0.696938222, 0.832246446, 0.73089346,
0.790965216, 0.799717389, 0.865896893, 0.946771069, 0.954212275,
1.023740345, 1.027036123, 1.086336263, 1.064542815, 0.9463809,
0.924081609, 0.999832641, 0.911277648, 0.922871168, 0.953134033,
0.786732115, 0.802026729, 0.832863371, 0.863952475, 0.817833153,
0.748586924, 0.72095701, 0.738213943, 0.672736744, 0.704947698,
0.531743532, 0.634123809, 0.683548549, 0.733277161, 0.608993729,
0.752162246, 0.568705823, 0.643172511, 0.597251486, 0.655514695,
0.583437677, 0.557676441, 0.646713866, 0.527005047, 0.578023512,
0.576281064, 0.600923204, 0.578475648, 0.551957027, 0.585007991,
0.623858699, 0.630936819, 0.636198589, 0.565476603, 0.658861425,
0.577557604, 0.629178306, 0.646092809, 0.566079299, 0.60953767,
0.680135261, 0.500802233, 0.704656678, 0.61109605, 0.645344144,
0.667139888, 0.734969576, 0.780062983, 0.783090234, 0.83005691,
0.905356723, 0.933746319, 0.947613375, 0.923115827, 0.873482691,
0.746883952, 0.850273618, 0.795256154, 0.800825928, 0.772630039,
0.749567395, 0.7823457, 0.772609842, 0.736269985, 0.699705666,
0.716860238, 0.65909369, 0.806743181, 0.604632102, 0.629103485,
0.669824708, 0.545219042, 0.605081484, 0.545598194, 0.612458887,
0.640840679, 0.568115521, 0.578270006, 0.642784637, 0.486235168,
0.608704086, 0.449107996, 0.603056279, 0.573624703, 0.527880861,
0.479058818, 0.608581986, 0.497792884, 0.736359035, 0.560758315,
0.59150912, 0.491623628, 0.646548159, 0.559243084, 0.554057512,
0.542344646, 0.583808567, 0.623315676, 0.521008383, 0.511710892,
0.633820855, 0.529775704, 0.590383598, 0.500021436, 0.602344336,
0.499887402, 0.534870849, 0.583225149, 0.623554367, 0.62596102,
0.585378422, 0.648988779, 0.577416685, 0.632021029, 0.644454559,
0.684966009, 0.595845502, 2.479315993, 2.683540753, 2.424790513,
2.556904106, 2.454032378, 2.486582811, 2.485804182, 2.625597071,
2.444459365, 2.649813652, 2.686066928, 3.124873535, 3.077318299,
3.297830917, 3.344358668, 3.589441204, 3.566707313, 3.968369009,
3.932341434, 4.08973781, 4.374551474, 4.54266808, 4.97884528,
4.932211371, 5.310903272, 5.372904082, 5.231493496, 5.123516042,
5.393849098, 5.276658613, 4.970827822, 4.972075355, 4.608769407,
4.214216452, 4.232190208, 4.539424798, 4.266998558, 3.933891331,
3.898577905, 3.758409871, 3.707152695, 3.544143355, 3.234304675,
3.312782898, 3.363897722, 3.32751203, 3.063968711, 3.396338279,
3.110947858, 3.27642981, 2.802338511, 2.972332411, 2.999566144,
2.860636811, 2.88545135, 2.715249006, 2.805430479, 2.734554555,
2.721654986, 2.81795618, 2.810857383, 2.829266791, 3.020586802,
3.108527475, 2.923112037, 2.898589704, 2.977292189, 2.961041296,
3.065747444, 2.883958043, 2.837869726, 2.918189185, 2.936651583,
2.760674734, 2.997230073, 2.888064962, 2.972304014, 3.162708107,
3.42147456, 3.577994842, 3.897689363, 4.134240754, 4.19746467,
4.937297252, 4.909702892, 4.974867813, 4.740338415, 4.369505261,
4.634231316, 4.530190201, 4.380129066, 4.246648651, 4.003376949,
4.261248528, 4.228186763, 4.190890809, 3.896217461, 4.019225536,
3.980007369, 3.985014169, 3.698733958, 3.417194347, 3.50155334,
3.527485148, 3.272718395, 3.228503258, 3.353819869, 3.104831527,
3.419528222, 3.010592683, 3.256523555, 3.020944643, 3.139582776,
2.872858156, 3.135211633, 3.047270457, 3.038848701, 2.843214189,
3.123247632, 2.958537301, 3.257263308, 3.138521527, 3.248321146,
2.963340122, 3.076476029, 2.987721452, 3.004584487, 2.906910601,
2.973867453, 3.0761696, 2.869900334, 2.78054149, 3.25876542,
2.978797901, 3.041764942, 3.029872905, 3.052446623, 2.856505763,
2.9962536, 3.015603327, 3.111149077, 2.9885447, 2.993520426,
3.176541902, 3.037954707, 2.975005669, 3.278917742, 3.137024394,
3.117943428)), row.names = c(NA, -745L), class = "data.frame")

Use geom_segment - this allows you to make use of the faceting variable. You will then want to pass a data frame with the respective x/xend/y/yend.
library(dplyr)
## create a data frame first for the segments
## it makes sense to use the mininimum of your y for each facet
annot_df <- melted_data %>%
group_by(variable) %>%
summarise(y = min(value), yend = min(value), x = 25, xend = 75)
ggplot(melted_data, aes(x = Distance, y = value, group = variable)) +
geom_line() +
## now use the new data frame for geom_segment
geom_segment(data = annot_df, aes(x = x, xend = xend, y = y, yend = yend),
arrow = arrow(ends = "both", length = unit(5, "pt"))) +
facet_wrap(variable~., scales = "free_y",ncol=2)
Created on 2022-07-14 by the reprex package (v2.0.1)

Related

Plotting multiple variables in time series with greyscale and shapes [duplicate]

This question already has answers here:
Changing the line type in the ggplot legend
(2 answers)
ggplot2 for grayscale printouts
(3 answers)
Closed 7 months ago.
I am trying to make a time-series graph with multiple y values. I would like to change the shape of the different variables so some are solid, some are dashed etc. I would also like all the colors to be on greyscale.
Does anyone know how I can accomplish this?
I know how to melt my data so that I can plot them all together by the value of the variables but right now I cannot get the shapes to change or the greyscale. Thank you in advance.
ggplot(melted_data, aes(x = Distance, y = value, color = variable)) + geom_line()
data <- structure(list(Distance = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
91, 92, 93, 94, 95, 96, 97, 98, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99), variable = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2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L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Mg",
"Mn", "Zn", "Ba"), class = "factor"), value = c(0.903247645,
0.912560748, 0.896003508, 0.909572697, 0.883631829, 0.905722594,
0.892465355, 0.909271173, 0.880506202, 0.889278401, 0.878534542,
0.959209459, 0.913303825, 0.929893977, 0.97778374, 0.9885554,
0.929716333, 1.028422583, 1.025638955, 1.011352651, 1.041343955,
1.092562951, 1.129761801, 1.088857171, 1.107257284, 1.116728405,
1.103053734, 1.041662037, 1.134182243, 1.104550315, 1.086952767,
1.106004784, 1.057688595, 1.034347579, 1.04641385, 1.139270945,
1.048446018, 1.033827731, 1.075554754, 1.029893202, 1.074749532,
1.001626205, 0.977053541, 0.987467665, 0.999540478, 0.945184816,
0.959677178, 0.962807712, 0.967023936, 1.024286493, 0.881264816,
0.967181342, 1.000316876, 0.956168258, 1.003214572, 1.00047837,
0.940103474, 0.929875987, 0.928227112, 0.982410241, 0.983035162,
0.976666772, 1.019755049, 1.075189042, 0.975380543, 0.981316782,
0.986876269, 1.026690916, 1.052379934, 1.001547298, 0.979888683,
1.008209647, 0.976098272, 0.944479556, 0.996767684, 1.018077758,
1.028862706, 1.08510417, 1.08963868, 1.048481179, 1.139954126,
1.107066353, 1.122920581, 1.23904326, 1.19449336, 1.179971969,
1.165865352, 1.068804094, 1.099436469, 1.073307737, 1.07045113,
1.101007051, 1.011962649, 1.11202545, 1.097883672, 1.05361424,
0.993283703, 1.046635444, 1.04951188, 0.086720869, 0.113119382,
0.088197332, 0.081547788, 0.079373211, 0.07888827, 0.072865285,
0.079637996, 0.066314774, 0.097585729, 0.185034982, 0.214466904,
0.294317625, 0.481389256, 0.531196058, 0.715842439, 0.865098887,
0.987242052, 1.081028291, 1.240920518, 1.313524957, 1.543771699,
1.78495042, 1.746572555, 2.048760527, 2.101438775, 1.967474033,
2.000286925, 2.014020838, 1.924470659, 1.75696549, 1.786681246,
1.633290961, 1.455799758, 1.315346538, 1.435348984, 1.27887702,
1.152818928, 1.095127218, 0.987502349, 1.062278922, 0.898540082,
0.83617998, 0.889057689, 0.825563648, 0.788347646, 0.790973555,
0.775541228, 0.815063004, 0.848723108, 0.66783059, 0.672629631,
0.747809615, 0.72338158, 0.666220438, 0.664051795, 0.597260657,
0.689282162, 0.663808452, 0.678551141, 0.672917354, 0.686199986,
0.724202364, 0.746195474, 0.686135659, 0.654148537, 0.713488795,
0.72446665, 0.699529989, 0.630120423, 0.661767463, 0.663290351,
0.705879842, 0.709399338, 0.76228353, 0.714368918, 0.720561695,
0.837036666, 0.923882149, 1.014163852, 1.221410703, 1.315825246,
1.368054705, 1.641746627, 1.630198312, 1.698589629, 1.562956393,
1.427322658, 1.53964983, 1.574583495, 1.527101216, 1.380123116,
1.28649445, 1.29251968, 1.330565441, 1.317758525, 1.19292313,
1.217953538, 1.218591815, 0.746612627, 0.818368055, 0.696689824,
0.748702805, 0.717457681, 0.766243608, 0.805305259, 0.855909762,
0.803357905, 0.889646097, 0.854456208, 1.067795473, 1.051422575,
1.17061972, 1.138440648, 1.052796919, 1.040998633, 1.161739158,
1.025956799, 0.971567748, 1.072911493, 0.952121155, 1.040392714,
1.069745522, 1.068549198, 1.090194087, 1.214584829, 1.157485471,
1.245813376, 1.336359991, 1.204038397, 1.126255292, 1.131057736,
0.922042386, 1.037566449, 1.100852394, 1.121842367, 0.998657748,
1.006938923, 1.002800377, 0.897387497, 0.93902937, 0.889327622,
0.802133735, 0.855245047, 0.860702407, 0.704324249, 0.905827093,
0.760155095, 0.760247698, 0.655991619, 0.677006743, 0.668001976,
0.623410532, 0.569302474, 0.523713794, 0.690042836, 0.539115342,
0.528696218, 0.57851915, 0.60294784, 0.581392042, 0.65277069,
0.65620614, 0.625397246, 0.697647782, 0.6180657, 0.632326126,
0.684659215, 0.606197513, 0.630134281, 0.637151517, 0.574538208,
0.605993607, 0.533522181, 0.544522236, 0.577535469, 0.573427383,
0.672984155, 0.735286828, 0.7532343, 0.881292245, 0.801132661,
1.122761046, 1.137397845, 1.173190388, 1.138033979, 1.126494557,
1.144871399, 1.087042815, 0.981750792, 0.992888445, 0.955352455,
1.074357698, 1.027127808, 1.083248059, 1.010304962, 1.037776316,
1.052809984, 0.742734852, 0.839492568, 0.743899849, 0.817080816,
0.773569657, 0.735728339, 0.715168283, 0.78077814, 0.694280484,
0.773303425, 0.768041196, 0.883401699, 0.818274274, 0.715927964,
0.696938222, 0.832246446, 0.73089346, 0.790965216, 0.799717389,
0.865896893, 0.946771069, 0.954212275, 1.023740345, 1.027036123,
1.086336263, 1.064542815, 0.9463809, 0.924081609, 0.999832641,
0.911277648, 0.922871168, 0.953134033, 0.786732115, 0.802026729,
0.832863371, 0.863952475, 0.817833153, 0.748586924, 0.72095701,
0.738213943, 0.672736744, 0.704947698, 0.531743532, 0.634123809,
0.683548549, 0.733277161, 0.608993729, 0.752162246, 0.568705823,
0.643172511, 0.597251486, 0.655514695, 0.583437677, 0.557676441,
0.646713866, 0.527005047, 0.578023512, 0.576281064, 0.600923204,
0.578475648, 0.551957027, 0.585007991, 0.623858699, 0.630936819,
0.636198589, 0.565476603, 0.658861425, 0.577557604, 0.629178306,
0.646092809, 0.566079299, 0.60953767, 0.680135261, 0.500802233,
0.704656678, 0.61109605, 0.645344144, 0.667139888, 0.734969576,
0.780062983, 0.783090234, 0.83005691, 0.905356723, 0.933746319,
0.947613375, 0.923115827, 0.873482691, 0.746883952, 0.850273618,
0.795256154, 0.800825928, 0.772630039, 0.749567395, 0.7823457,
0.772609842, 0.736269985, 0.699705666, 0.716860238, 0.65909369
)), row.names = c(NA, -396L), class = "data.frame")
You can use the linetype parameter with the aestethics :
ggplot(data) +
geom_line(aes(x = Distance, y = value, color = variable, linetype = variable))

Heatmap in R does not display properly

This is the code I have for the heatmap.
sd1<-melt(Mstressed,id.vars = "Period")
library(plotly)
P1 <- ggplot(data=sd1, aes(x=Period, y=variable, fill=value)) +
geom_tile() +
ggtitle("Stress Portfolio Returns") +
scale_fill_gradientn(colors=colorRampPalette(c("lightgray","royalblue","seagreen","orange","red","brown"))(500),name="Returns") +
labs(x = "Period",y="Size") +
theme_bw()
ggplotly(P1)
Here is sd1 which is already in the melted format:
Period variable value
1 1 Size5 -1.124193e-03
2 2 Size5 2.859438e-05
3 3 Size5 -2.432560e-03
4 4 Size5 -2.544023e-03
5 5 Size5 -1.577432e-03
6 6 Size5 -1.480790e-03
and here it is sd1
> dput(sd1)
structure(list(Period = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170,
171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,
223, 224, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212,
213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128
), variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1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L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Size5", "Size15", "Size25",
"Size50", NA), class = "factor"), value = c(-0.0011241931, 2.85943772727272e-05,
-0.00243256027727273, -0.00254402339069767, -0.00157743184782609,
-0.00148078985416667, -0.00331852698695652, 0.000848599395833333,
-0.00297349628181818, -0.000345186711111111, -0.000501344534782609,
-0.000800074080851064, -0.00221098331428571, 0.00129236565531915,
-0.00131892916086957, -0.00177610596170213, -0.00319288334468085,
0.00113381609787234, -0.00107374819148936, -0.00144620190638298,
0.000141176244444444, -0.000204472952173913, -0.00153988329130435,
3.81790045454546e-05, -0.0011685701173913, 0.000593231404255319,
0.00081186575, 0.000795386733333333, -0.00260122034583333, -0.0021938114875,
0.000553855472340425, -0.0059582546893617, 0.868693839468085,
-0.002801906475, -0.00463708955833333, -0.00272099271111111,
0.00108590003333333, -0.00247600357826087, -0.00372859965957447,
0.000286994587234042, 0.000746639587234043, 0.000276679165957447,
-0.001046501125, 0.0001712814375, -0.0024568735875, 0.000996786336170213,
-0.00182627393191489, -0.000544925195652174, -0.00357635526086957,
-0.00054329072173913, 0.00013407957826087, -0.00103177774347826,
0.000500834638297872, 0.793977075161702, -7.5436685106383e-05,
-0.000485326586956522, -0.000606974591304348, 0.00238437179166667,
0.00100126108888889, -0.000513758953191489, 8.69377181818182e-05,
-0.00123867083829787, 1.3438354628383, -0.00031518505, -0.00191560200454545,
0.805996328804348, -2.61513454545454e-05, -0.000103250163636364,
-0.000778098191489362, -0.0015234903, -0.00114211408636364, -0.00159511182978723,
1.87802078087826, 6.72123086956521e-05, 0.00100891171111111,
-0.000902390629787234, 0.0011009548, 0.000312209177777778, -0.000768029209090909,
-0.000303889769565218, 2.55336222222222e-05, -0.000205546365217391,
0.000216974877272727, 1.47901930388571, -0.000277860133333333,
-0.000214537138095238, -0.00209356162222222, 8.97567761904762e-05,
-0.00559485620909091, 0.000268375711111111, 1.39724291668889,
0.000208154288888889, -0.000634756711111111, 1.22926746946512,
0.00201531319534884, 0.252617265511111, -0.00113930945106383,
0.000837345108695652, 0.00246463208780488, 0.000899249748837209,
0.00274860853333333, 0.00547736369047619, 0.00163468337674419,
-0.000276660977272727, -0.00149508101818182, -0.00221645797777778,
0.00217117751363636, -0.0024888984, -0.000886121655813954, 1.04398107523478,
0.00393339840930233, -0.000922796323809524, -0.00103749403636364,
0.0028039828, 0.00551933685, -0.00123477008888889, -0.005628441,
-0.00121736573043478, -0.000539308567441861, 0.000262361868181818,
0.000343038088888889, -0.0019510897, -0.00288396375454546, 0.359000083955556,
0.000433049466666666, 1.36924029128889, -0.000659901990909091,
0.00304780745454545, 0.000657599762790698, -0.00163171464444444,
-0.000950691240909091, 0.00140542772727273, -0.00107216327272727,
0.000923795111111111, -0.000474348352173913, -0.000865860582608696,
-0.00326246348888889, -0.0006538472, 0.000691390128571429, -9.56189619047619e-05,
-0.00127241684651163, 0.000941450827272727, 0.000531463427906977,
-0.0024702198, 1.36070394653333, -0.00128264022222222, -0.000889438852173913,
-0.000750582844444444, -0.000299201959090909, -0.00191169516363636,
-0.000670931155555555, 2.36634136363636e-05, -0.00117427344186047,
-0.00024379075, -0.000986528844444444, 0.000683873, -0.00243973785909091,
-0.00394431812727273, -0.00293166445, -0.00264133897021277, 0.0029811113627907,
-0.00108674306666667, -0.00145431042727273, 0.00250975572340426,
0.0009900039, -0.00208648798636364, -3.64380465116271e-06, 0.000535875804545454,
0.00197072025217391, -0.00175674031111111, -0.00122569961276596,
1.77897318181817e-05, 0.000638891873913043, -0.000582162311111111,
0.00169907495555556, -0.0017897038826087, 0.657609502855814,
-0.00276549255555556, 0.000570080259574468, 0.00242968832272727,
-0.000416251471428571, 0.000278305236363636, -0.000308473874418605,
0.0015745695875, -0.00119187120476191, 0.00315008771111111, 0.624268614481818,
0.000191677111111111, 0.26118118567234, 0.00184649572608696,
-0.00148222706521739, -0.00224949090232558, -0.00098840725, -0.000267329995744681,
-0.00113342224680851, -0.000558455731914894, 0.000867598088888889,
0.000182637295454545, 0.000666522423255814, -0.000249393468181818,
0.00137624896744186, -0.000641461824390244, -0.000726498320930232,
0.0002189695, 0.000304278144186047, -0.000552308133333333, -8.48839142857143e-05,
2.33358333333333e-05, -0.000115722561904762, 0.91983811283913,
-0.000417791762790698, -0.000322370023255814, -0.000398199302127659,
-9.84947333333333e-05, -0.00031643990952381, -0.000323731279069767,
-0.0006542225, -0.000273647675, 1.15457317073172e-05, -7.34662954545455e-05,
-0.000362220495238095, -0.000537859323809524, -8.60688604651162e-05,
-0.000820713952380952, -0.00153372003333333, -0.000662153756060606,
-0.00275888667727273, -0.00292078759069767, -0.00191772458115942,
-0.000874108720833333, -0.00347106492028986, 0.000208326329166667,
-0.00348595174848485, 0.324998960088889, -0.000291810668115942,
-0.0026285438141844, -0.00318451878095238, 0.00141962778865248,
0.54385947323913, -0.00152278529503546, -0.00409083314468085,
0.195643822364539, -0.000821318458156028, 0.481235884893617,
0.000631022044444445, -0.000154888085507247, -0.00238089515797101,
0.000598294737878788, -0.000853384650724638, 0.00126600480425532,
0.317600938083333, 0.000601763333333333, -0.00106298107916667,
0.316528564245833, 0.000802788139007092, -0.00681549495602837,
0.288553514534752, -0.001983084275, -0.00462916789166667, -0.00399624291111111,
0.00133947723333333, -0.00233989184492754, -0.00326993565957447,
-5.17553460992909e-05, 0.000316770853900709, 0.114606201365957,
0.311149128608333, 0.0994249547041667, -0.00179180045416667,
0.000758236002836879, -0.00229026533191489, -0.000906085528985507,
-0.0034218825942029, 0.411083387011594, 0.407663510978261, -0.000700014143478261,
9.04682382978723e-05, 0.264309987961702, 4.96020482269504e-05,
-0.00112393678695652, -0.00112170092463768, 0.00237529965833333,
-0.000567775777777778, -0.000236103953191489, 0.000608177318181818,
-0.00102851437163121, 0.448221119304964, 0.13397610235, -0.00241395220454545,
0.443765600537681, -0.000226488945454545, 0.000616203103030303,
-0.0013208753248227, -0.000716755566666667, 0.091597368380303,
-0.00170434656312057, 0.626332195011594, 0.000150197242028985,
0.000136383977777778, 0.381103545036879, 0.221540732266667, 0.360871791444444,
-0.000592961009090909, 0.000155833097101449, -0.000866745711111111,
0.000216817234782609, 0.609538703077273, 0.645238149819048, -0.000398335866666667,
-0.000344592138095238, -0.00137507775555556, -0.000256117023809524,
-0.00192587620909091, -6.42416888888889e-05, 1.02013637508889,
-9.28306444444445e-05, -0.00147465644444444, 0.409911313531783,
0.0019891590620155, 0.0851806975111111, -0.00204437158439716,
-0.000579642224637681, 0.000905066487804878, 0.643067721215504,
0.00147966286666667, 0.00508458082380952, 0.000539691310077519,
0.240211235089394, -0.000708393018181818, -0.00109935424444444,
0.0026950974469697, 0.6396645562, -0.00126269592248062, 0.347808651568116,
0.00457931780930233, 0.000302961476190476, -0.0012148691030303,
0.0923351892, 0.00567091231666667, 0.620369322511111, -0.00404364773333333,
-0.00241288513043478, 0.202742444965891, -0.000608278798484849,
0.000356460755555555, -0.00161257603333333, -0.00190840115454545,
0.120414817088889, 0.2228905758, 0.455057063555556, -0.000602834124242424,
0.00261724412121212, 0.452285066562791, -0.00246991411111111,
-0.00152651097424242, 0.000518139793939394, -0.00184454593939394,
0.000185236244444444, -0.00128692128550725, -0.000827895915942029,
-0.00243018582222222, -0.00120132326666667, 0.416215973261905,
0.000253243971428571, -0.00170670997984496, 0.000686898960606061,
-0.00033481963875969, -0.0020584786, 0.4539038956, -0.00121793155555556,
-0.00123285105217391, -0.000559311711111111, 0.000337146574242424,
-0.00228272816363636, -0.00138098148888889, -0.000646004586363636,
-0.0014501903751938, -7.21782833333334e-05, -0.000256129177777778,
0.000223322266666667, -0.00308267385909091, -0.00280884286060606,
-0.00280925431666667, -0.00175704863687943, 0.380177369362791,
-0.0012472598, -0.00215720449393939, 0.00190565352340426, 0.000277635766666667,
-0.00224420778636364, -0.000902296071317829, 0.00110526400454545,
0.00164177331884058, -0.000970322977777778, 0.488807391653901,
-0.000405886401515152, -0.000386372792753623, -0.000187081244444444,
0.00191570668888889, -0.00188197921594203, 0.219782496255814,
-0.00182879988888889, 4.84401929078014e-05, 0.000748088722727273,
-0.0012550096047619, 0.000173737503030303, -0.000151241941085271,
0.581544109520833, -0.00156196413809524, 0.00255382897777778,
0.208691561081818, 0.664795524311111, 0.42483048627234, 0.00175584192608696,
0.201560880468116, -0.00209381856899225, 0.000321025016666667,
-0.000421247062411348, -0.00215724371347518, 0.646012675801418,
0.350737970755556, 0.178416441162121, 0.00103144908992248, -0.000187515334848485,
0.000174517300775194, -0.000258069957723577, -0.00119511305426357,
0.0003255877, 0.00023375347751938, -0.0005782456, -0.000402424114285714,
0.1384140809, 0.418395168104762, 0.306135187705797, -0.00102090409612403,
-0.000444740023255814, 0.138124852631206, -0.0004063458, 0.00029016809047619,
-0.000799771212403101, -0.000183847566666667, 0.000114925325,
-0.000269002668292683, -0.000733895628787879, -0.000981041028571429,
-0.000873523457142857, 3.48687286821712e-06, -0.00107125035238095,
0.36082286618, -0.000514447102727273, -0.00280299127727273, -0.00263217947069767,
-0.00203968404782609, -0.000458293174166667, -0.00351976894695652,
0.000204725635833333, -0.00339431988181818, 0.193479343088889,
0.000112535625217391, -0.00213525120085106, -0.00288490815428571,
0.343934077535319, 0.32598547811913, 0.155322520318298, -0.00360304194468085,
0.116695380217872, -0.00115564579148936, 0.288642051333617, 0.00110193360444444,
0.000231925527826087, -0.00271350401130435, 0.000528825044545455,
-0.000843372957391304, 0.00152301136425532, 0.42680129887, 0.000348928813333333,
-0.00106065298583333, 0.1891960110325, 0.00144156823234043, -0.0058980177693617,
0.172238823228085, 0.180649895645, -0.00399227711833333, -0.00396987499111111,
-0.000279930486666667, -0.00221300633826087, -0.00437551217957447,
0.373557485947234, -0.000553946612765957, 0.180780737205957,
0.186384874315, 0.0601822571175, -0.0013033474675, 0.000607181016170213,
-0.00182825481191489, -0.00101525615565217, -0.00307393246086957,
0.246870552998261, 0.244639116138261, -9.59920234782608e-05,
0.00103178067829787, 0.158475002401702, 0.0957530407148936, -0.00108818790695652,
-0.00106499063130435, 0.00182353239166667, -0.000770247991111111,
0.251169645886809, 0.00135098203818182, -0.00106422307829787,
0.268188202118298, 0.08014729743, 0.173129845155455, 0.266595692084348,
-0.000510779745454545, 0.000609720036363636, -0.000709136471489362,
-0.00074677718, 0.273296411113636, -0.00150910594978723, 0.375676878958261,
-7.46597313043479e-05, 0.222301664431111, 0.599549396090213,
0.13323872568, 0.216335941017778, -0.000372647409090909, 0.000250945590434783,
-0.000609455297777778, 0.163203653554783, 0.365593381717273,
0.387049939765714, 0.377756158386667, -0.000608418738095238,
-0.000877734902222222, 0.29536194985619, -0.00151932240909091,
8.84523111111115e-06, 0.887420447928889, 6.04058888888889e-05,
-0.00168793287111111, 0.245879004745116, 0.00210788515534884,
0.0518048467911111, -0.00204896865106383, -0.000766938131304348,
0.000369568767804878, 0.385807118748837, 0.00125597745333333,
0.00342261065047619, 0.000917297056744186, 0.145203749862727,
-0.000608651458181818, -0.000619898377777778, 0.00255708987363636,
0.46996938808, 0.0463716679041861, 0.209438538634783, 0.00629131560930233,
0.000908092756190476, 0.118311483963636, 0.055266674, 0.00411797937,
0.371606156751111, -0.00341520444, -0.00207519669043478, 0.388790875192558,
0.382199056508182, 0.000288075208888889, -0.00233150982, 0.190417886325455,
0.367062582115556, 0.133206785506667, 0.591484569088889, -0.000679957030909091,
0.00235175421454545, 0.271733587002791, -0.00258801096444444,
0.209600095759091, 0.268993620327273, -0.00175308111272727, 0.000141544911111111,
-0.00146279359217391, -0.000720371102608696, -0.00227193868888889,
-0.00099748604, 0.249673461088571, 0.00122685363809524, -0.00157589268651163,
0.000390671067272727, -0.000246003732093023, -0.00189639072,
0.272506430813333, -0.00121220570222222, -0.00129201353217391,
-0.000471348084444445, 0.108562531000909, -0.00230415824363636,
-0.00146539943555556, -0.000698085466363636, -0.00125351572186047,
0.32477301345, -0.000655153204444444, 0.23415397968, -0.00311150981909091,
-0.00240564984727273, -0.00271525109, 0.124826008829787, 0.228650982202791,
-0.000831444746666667, -0.00208768206727273, 0.00210693784340426,
-0.00032504578, -0.00201565726636364, -0.00121992036465116, 0.241373214804545,
0.00180044913217391, -0.00144649063111111, 0.293257521547234,
0.156942076691818, -0.000396712526086957, 0.333872094768889,
0.00126618459555556, -0.0022017223626087, 0.132416393375814,
-0.00154369867555556, -0.000127951540425532, 0.000643781042727273,
-0.00149518583142857, 0.000159095756363636, 0.431103792525581,
0.3497642155475, -0.0010894085247619, 0.00271588987111111, 0.347565654681818,
0.554514602551111, 0.25466477267234, 0.00141746724608696, 0.120691384734783,
-0.00244462910232558, 0.06381322055, -0.000572060355744681, 0.212942333313191,
0.387555468868085, 0.210574743968889, 0.107224934255455, 0.00119969578325581,
-0.000265811628181818, -0.00014974783255814, -6.32937443902438e-05,
-0.00163017968093023, 0.00031326598, -0.000229250015813954, 0.281825955426667,
-0.000219622714285714, 0.0828831356333333, 0.251266484118095,
0.18387889279913, -0.000723895042790698, 0.362715330336744, 0.0829555198178723,
-0.000342741853333333, 0.00098233181047619, 3.61713209302325e-05,
0.00060474866, 0.000214934285, -0.000507613948292683, -0.00126401089545455,
0.295409336744762, 0.49940544567619, 0.000444745259534884, 0.075755845887619,
0.2663678565, -0.00112328892272727, -0.00252072917727273, 0.0919692581493023,
-0.00293427190782609, -7.54536341666666e-05, -0.00354078930695652,
2.57954158333333e-05, -0.00262876556181818, 0.0960986548688889,
-0.000307806654782609, -0.00256542482085106, -0.00344343351428571,
0.171732012655319, 0.16290640195913, 0.0771365308982979, -0.00323413486468085,
0.239592012997872, 0.0929770842485106, 0.143919237313617, 0.0872022225044444,
-0.000374014952173913, -0.00198149831130435, 0.150230880804545,
0.0495306889826087, 0.00207576486425532, 0.21266222853, 6.23467733333334e-05,
-0.000502785265833333, 0.1146813025125, 0.00236195601234043,
-0.0055398928293617, 0.0850331580480851, 0.091095192845, -0.00308972659833333,
-0.00268806053111111, -0.000621778406666667, -0.00211494293826087,
0.0788185111804255, 0.187436011507234, -0.00105928309276596,
0.273111877825957, 0.091654408075, 0.1881146334375, -0.0012845890675,
0.000535671256170213, 0.261780701048085, -0.00130433873565217,
0.0672782252391304, 0.123152524898261, 0.122219372418261, 0.108913352556522,
0.00154812281829787, 0.0787473360617021, 0.208401497354894, 0.0494821097730435,
-0.00100385527130435, 0.00179214179166667, -0.00113253543111111,
0.125312734706809, 0.00112138269818182, -0.000824940378297872,
0.133558478718298, 0.06196782193, 0.0853069711554545, 0.227115156824348,
-0.000573424825454545, 0.147897520156364, 0.0948538439485106,
-0.00102526364, 0.136662496333636, 0.0497748200102128, 0.327559354018261,
0.158837548148696, 0.111405826131111, 0.472707361930213, 0.15095515508,
0.108453752477778, -0.000742863369090909, 0.000265612850434783,
0.187649188042222, 0.277873906394783, 0.417418378297273, 0.383188042745714,
0.188476248766667, -0.000679375438095238, -0.000940556842222222,
0.14747278479619, -0.00116911116909091, 0.193063097831111, 0.443910019148889,
0.156860665528889, -0.00140947317111111, 0.194701012465116, 0.179753437755349,
0.0271931040711111, -0.00148793193106383, -0.000247921611304348,
0.0215570688078049, 0.193278326948837, 0.269718930653333, 0.00265989913047619,
0.00111463559674419, 0.0727459556427273, 0.178373261021818, 0.0498605999422222,
0.00285280777363636, 0.28503765544, 0.0225589752241861, 0.105547501674783,
0.00522300738930233, 0.000134479296190476, 0.0587813904836364,
0.02802175016, 0.17572127429, 0.184946720591111, -0.00234486358,
-0.00230577149043478, 0.194051282172558, 0.250351470368182, 0.143461193228889,
-0.00273105342, 0.0943393136254545, 0.184555788855556, 0.0659578766466666,
0.294674815488889, -0.000197858810909091, 0.135317324614545)), row.names = c(NA,
800L), class = "data.frame")
This is the plot i get which is incorrect, I am very confused as I am sure it was working in the past that code, as well as I am sure the syntax is correct! Obviously i must be missing something.
Given your data and script, the plot looks ok on my computer (see below). Which version have you used?
library("plotly")
P1 <- ggplot(data=sd1, aes(x=Period, y=variable, fill=value)) +
geom_tile() +
ggtitle("Stress Portfolio Returns") +
scale_fill_gradientn(colors=colorRampPalette(c("lightgray","royalblue","seagreen","orange","red","brown"))(500),name="Returns") +
labs(x = "Period",y="Size") +
theme_bw()
ggplotly(P1)
I recommend to follow the advice of #Dan Adams. It may also help to check the versions of R and packages. Here a part of my SessionInfo (only R version and attached packages shown).
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
# ... omitted
other attached packages:
[1] plotly_4.10.0 ggplot2_3.3.5
# ... omitted

R get linear regression equation for boxplots

I didn´t found a sufficient answer in this forum yet, so I decided to raise my own question.
I want to get the linear regression equation of a linear fit from a boxplot. I have this data:
library(ggplot2)
data <- structure(list(x =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, 71, 141, 218, 7.5,
1, 129, 144.5, 76, 46.5, 75.5, 45, 12, 24, 67, 65.5, 44.5,
37.5, 25.5, 19, 15, 1, 17.5, 50, 22.5, 90, 226, 220, 32,
69.5, 1, 79.5, 7, 44, 1, 15.5, 22, 75.5, 178, 153, 4.5, 1,
159, 89, 57, 71, 98.5, 47.5, 18.5, 30, 119, 57.5, 41, 33.5,
30, 31, 10, 1, 12, 43.5, 20.5, 98, 146.5, 145, 34, 64.5,
1, 40.5, 17, 41, 1, 14.5, 16.5, 71, 181, 168, 2, 1, 159,
103, 69, 65.5, 97.5, 37.5, 21, 15.5, 120.5, 46, 27, 29.5,
16.5, 20, 7.5, 1, 15.5, 42.5, 21.5, 111, 102.5, 124, 20.5,
51.5, 1, 22.5, 15, 42, 1, 13, 13.5, 64.5, 138, 155, 4.9,
1, 190, 89.5, 74.5, 79, 78, 59.5, 19.5, 21, 88.5, 44, 18,
19, 10, 13, 4, 1, 9.5, 44, 17, 140.5, 98, 112.5, 29.5, 62.56,
1, 31, 11.5, 49.5, 1, 10, 8.5, 40.5, 121, 141, 2.5, 1, 170,
87.5, 92, 77, 65, 34, 8, 26, 98, 51.5, 26, 19, 9, 8.5, 7.5,
1, 4.5, 0, 15.5, 80, 69, 59, 28, 44.5, 1, 38.5, 10, 51.5,
1, 3, 5, 65, 107, 152, 5, 1)), row.names = c(NA, -216L), class = "data.frame")
p <- ggplot(data = data) +
aes(x = x,
y = y) +
geom_boxplot(outlier.shape = NA) + geom_jitter(shape = 1, position = position_jitter(0.1)) +
ylim(0, NA) +
theme_light() +
geom_smooth(method = "lm",se = TRUE, formula = y ~ x, aes(group = 1))
print(p)
fit <- lm(y ~ x, data = data)
fit
which results in this output:
How can I extract the regression equation for this dataset? The function fit <- lm(y ~ x, data = data) just gives me one intercept and 5 coefficients, which is not my desired output. I want a simple regression equation in the form of y = a + bx.
How can I put this equation into the diagramm? I´ve already looked into ggpmisc::stat_poly_eq(), but this doesn´t seem to work with boxplot linear regression.
Can you guys help me out?

ggplot2 - Survival Swimmer Plot Not Displaying Sorted Values

Using this question I've been assembling a customized Swimmer Plot, but despite my having sorted the patients by Therapy.Length, when I try to plot it the second half of the bars often come out much longer than they should be - putting the graph out of order.
I've checked and the symbols are in the correct place even when the bar is too long, so somehow the bar lengths are getting extended. By commenting out scale_y_continuous chunk, I'm able to get the proper length on the bars, but then all of the symbol placement is compressed.
ggplot(dat,
aes(Patient.ID, Therapy.Length)) +
geom_bar(stat="identity", aes(fill=factor(Disease.Stage)), width=0.7) +
geom_point(data=dat, aes(Patient.ID, value, colour=variable, shape=variable), size=4) +
geom_segment(data=dat %>% filter(Continued == 1),
aes(x=Patient.ID, xend=Patient.ID, y=Therapy.Length + 0.1, yend=Therapy.Length + 20),
arrow=arrow(type="closed", length=unit(0.13,"in"))) +
coord_flip() +
scale_fill_manual(values=hcl(seq(15,375,length.out=5)[1:4],100,70)) +
scale_colour_manual(values=c(hcl(seq(15,375,length.out=3)[1:2],100,40),c("black","darkgreen"))) +
scale_y_continuous(limits=c(-1,max(dat$Therapy.Length)), breaks=seq(0,max(dat$Therapy.Length),30)) +
labs(fill="Disease Stage", colour="", shape="", x="Subject Received Study Drug")
+ theme_bw() +
theme(panel.grid.minor=element_blank(),panel.grid.major=element_blank(),
axis.text.y=element_blank(),axis.ticks.y=element_blank())
Here's the rest of the code: [x]
ANSWER:
dat had originally been melted – changed dat to be unmelted (and created dat.m to be the melted version), and supplied dat.mto geom_point and geom_segment for adding points to bars.
data:
structure(list(Patient.ID = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L), .Label = c("13",
"5", "14", "11", "6", "2", "7", "12", "3", "8", "1", "10", "4",
"15", "9"), class = "factor"), Disease.Stage = c(1L, 2L, 4L,
1L, 2L, 3L, 1L, 1L, 3L, 2L, 1L, 1L, 3L, 2L, 3L, 1L, 2L, 4L, 1L,
2L, 3L, 1L, 1L, 3L, 2L, 1L, 1L, 3L, 2L, 3L, 1L, 2L, 4L, 1L, 2L,
3L, 1L, 1L, 3L, 2L, 1L, 1L, 3L, 2L, 3L, 1L, 2L, 4L, 1L, 2L, 3L,
1L, 1L, 3L, 2L, 1L, 1L, 3L, 2L, 3L), Response.Start = c(15, 40,
51, 26, 36, 26, 32, 43, 67, 80, 93, 105, 160, 34, 94, 15, 40,
51, 26, 36, 26, 32, 43, 67, 80, 93, 105, 160, 34, 94, 15, 40,
51, 26, 36, 26, 32, 43, 67, 80, 93, 105, 160, 34, 94, 15, 40,
51, 26, 36, 26, 32, 43, 67, 80, 93, 105, 160, 34, 94), Therapy.Length = c(74,
84, 84, 108, 128, 185, 194, 198, 257, 274, 293, 311, 325, 336,
357, 74, 84, 84, 108, 128, 185, 194, 198, 257, 274, 293, 311,
325, 336, 357, 74, 84, 84, 108, 128, 185, 194, 198, 257, 274,
293, 311, 325, 336, 357, 74, 84, 84, 108, 128, 185, 194, 198,
257, 274, 293, 311, 325, 336, 357), Continued = c(1, 1, 1, NA,
1, NA, 1, NA, 1, NA, 1, NA, 1, NA, 1, 1, 1, 1, NA, 1, NA, 1,
NA, 1, NA, 1, NA, 1, NA, 1, 1, 1, 1, NA, 1, NA, 1, NA, 1, NA,
1, NA, 1, NA, 1, 1, 1, 1, NA, 1, NA, 1, NA, 1, NA, 1, NA, 1,
NA, 1), variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L), .Label = c("Response.End", "Durable", "Complete",
"Partial"), class = "factor"), value = c(40, 78, 78, 106, 89,
177, 108, 101, 138, 209, 279, 244, 311, 167, 271, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, -1, NA, NA, NA, NA, NA, 40, NA, NA,
NA, NA, 32, 43, NA, NA, 93, NA, 160, NA, 94, 15, NA, 51, 26,
36, 26, NA, NA, 67, 80, NA, 105, NA, 34, NA)), row.names = c(NA,
-60L), .Names = c("Patient.ID", "Disease.Stage", "Response.Start",
"Therapy.Length", "Continued", "variable", "value"), class = "data.frame")

How to make beanplot and boxplot in the same chart?

seasons <- structure(list(values = c(204, 339, 304, 434, 334, 212, 361,
102, 298, 369, 149, 227, 278, 199, 360, 211, 219, 209, 177, 299,
262, 285, 237, 227, 216, 229, 317, 321, 327, 123, 84, 321, 442,
263, 225, 290, 259, 219, 244, 325, 257, 672, 762, 381, 698, 578,
576, 386, 834, 790, 815, 736, 517, 556, 685, 781, 703, 1071,
537, 784, 753, 790, 489, 878, 433, 742, 638, 731, 1017, 850,
804, 612, 923, 1000, 855, 750, 921, 676, 621, 781, 703, 1054,
156, 312, 267, 152, 352, 155, 215, 184, 186, 221, 352, 183, 307,
353, 507, 255, 159, 109, 343, 377, 209, 260, 193, 231, 111, 167,
233, 360, 488, 347, 208, 178, 371, 276, 263, 166, 486, 119, 153,
315, 226, 158, 142, 78, 75, 156, 53, 103, 141, 94, 94, 55, 84,
35, 82, 65, 150, 30, 201, 184, 94, 119, 150, 70, 63, 50, 74,
160, 49, 52, 135, 105, 129, 75, 83, 85, 84, 85, 77, 147, 100,
46), ind = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("spring",
"summer", "autumn", "winter"), class = "factor", scores = structure(c(3,
1, 2, 4), .Dim = 4L, .Dimnames = list(c("autumn", "spring", "summer",
"winter"))))), .Names = c("values", "ind"), row.names = c(NA,
-164L), class = "data.frame")
I made a boxplot and beanplot below.
boxplot(seasons$values~seasons$ind, ylim= c(0,1200))
beanplot(seasons$values~seasons$ind, ylim= c(0,1200),
col = c("#CAB2D6", "#33A02C", "#B2DF8A"), border = "#CAB2D6", side="second")
I want to make a chart containing these boxplot and beanplot at the same time.
This would make comparison easy. Thai is why I made same ylim on both plots.
Is there any way I can do?
With beanplot package, use add=TRUE:
boxplot(seasons$values~seasons$ind, ylim= c(0,1200))
beanplot(seasons$values~seasons$ind, ylim= c(0,1200), col = c("#CAB2D6", "#33A02C", "#B2DF8A"), border = "#CAB2D6", side="second", add=T)
Try with ggplot:
ggplot(seasons, aes(x=ind, y=values))+geom_boxplot()+geom_violin(fill='lightblue', alpha=0.5)+geom_jitter(position = position_jitter(width = .1))

Resources