我有以下结果,我正在尝试使用下面的代码使用ggplot
列进行绘图,但是排序使得图例上的第一个排名图对应于最高分(取自最后一行)数据)。因此,例如,绘图将按以下方式排序,在图例上将如下所示;
train_auc_9 (result = 0.9939489)
train_auc_6 (result = 0.9870544)
train_auc_3 (result = 0.9699427)
train_auc_8 (result = 0.9662169)
train_auc_7 (result = 0.9662169) etc.
我应该先根据final
行值对列进行排序,以使生活更轻松吗?
ggplot代码:
ggplot(result_train_auc, aes(ID)) +
geom_line(aes(y = train_auc_1, colour = "train_auc_1")) +
geom_line(aes(y = train_auc_2, colour = "train_auc_2")) +
geom_line(aes(y = train_auc_3, colour = "train_auc_3")) +
geom_line(aes(y = train_auc_4, colour = "train_auc_4")) +
geom_line(aes(y = train_auc_5, colour = "train_auc_5")) +
geom_line(aes(y = train_auc_6, colour = "train_auc_5")) +
geom_line(aes(y = train_auc_7, colour = "train_auc_6")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_7")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_8")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_9"))
ggtitle("auc curves") +
labs(y="auc result", x = "rounds") +
theme_bw(base_size = 11, base_family = "")
数据的最后一行。
0.9177697
0.9309705
0.9699427
0.9431463
0.9544374
0.9870544
0.9538312
0.9662169
0.9939489
100
数据称为result_train_auc
。
structure(list(train_auc_1 = c(0.8713344, 0.8871179, 0.8928057,
0.8964518, 0.8976864, 0.8995532, 0.9001708, 0.9015733, 0.9022265,
0.9027288, 0.9031676, 0.9036361, 0.9040329, 0.9045184, 0.9048802,
0.9053402, 0.9055032, 0.9056735, 0.9061118, 0.9062926, 0.9064719,
0.9067036, 0.9069563, 0.9071833, 0.9074455, 0.907724, 0.907817,
0.9081296, 0.9082689, 0.9084679, 0.9086163, 0.9087718, 0.9091238,
0.9093731, 0.9095402, 0.909702, 0.909771, 0.9099373, 0.9101334,
0.9103078, 0.9104885, 0.9106456, 0.9107819, 0.9108925, 0.9111391,
0.9112471, 0.9114579, 0.9115598, 0.9116752, 0.9117411, 0.9118367,
0.9120177, 0.9121465, 0.9123075, 0.9125142, 0.9125989, 0.9127896,
0.9128665, 0.9129764, 0.9130837, 0.9132152, 0.9133399, 0.9135001,
0.9136408, 0.9137385, 0.9138751, 0.9139981, 0.9140897, 0.914189,
0.9142859, 0.9144037, 0.9145455, 0.9146629, 0.9147381, 0.9148613,
0.9149902, 0.9150876, 0.9151985, 0.9153009, 0.9154068, 0.915529,
0.9156637, 0.9157626, 0.9158646, 0.915995, 0.9161135, 0.9162173,
0.9163324, 0.91642, 0.9165297, 0.9166981, 0.9168092, 0.9169468,
0.9170768, 0.9171896, 0.9173152, 0.9174244, 0.9175383, 0.9176803,
0.9177697), train_auc_2 = c(0.8870459, 0.9021414, 0.9085472,
0.9114717, 0.9136837, 0.9148831, 0.9160633, 0.916577, 0.9175609,
0.918181, 0.9185195, 0.9189418, 0.919285, 0.9195346, 0.9197795,
0.9201756, 0.9205287, 0.9207205, 0.9208646, 0.9210185, 0.9211867,
0.9213273, 0.9214634, 0.9217073, 0.921851, 0.9220127, 0.9221905,
0.9224531, 0.9227193, 0.9228104, 0.9229566, 0.9231306, 0.9233425,
0.9234565, 0.9235739, 0.9237399, 0.9239113, 0.9240052, 0.9242447,
0.9243938, 0.9245815, 0.9247349, 0.92491, 0.9250047, 0.9251303,
0.9252628, 0.925474, 0.9256335, 0.9257628, 0.9258756, 0.9259525,
0.9260501, 0.9261603, 0.9262516, 0.926404, 0.9264811, 0.9266122,
0.9267074, 0.9268346, 0.9269162, 0.9270102, 0.9271369, 0.9272119,
0.9273092, 0.9274163, 0.9275176, 0.9276396, 0.9277829, 0.9278664,
0.927978, 0.928066, 0.9281753, 0.9283186, 0.928417, 0.9285194,
0.9286077, 0.9286985, 0.9287818, 0.9288713, 0.9289982, 0.9290624,
0.9291517, 0.929267, 0.9293397, 0.9294468, 0.9295616, 0.9296748,
0.9297741, 0.9298962, 0.929982, 0.9300875, 0.9301889, 0.9302799,
0.9303726, 0.9304612, 0.930582, 0.9306869, 0.9307636, 0.9308679,
0.9309705), train_auc_3 = c(0.920364, 0.9396713, 0.9477804, 0.9511932,
0.9533659, 0.9548309, 0.9560987, 0.9569889, 0.9577224, 0.9580906,
0.9585115, 0.9590348, 0.9592664, 0.9596969, 0.9600961, 0.9603775,
0.9605959, 0.9608837, 0.9611088, 0.9612673, 0.9614595, 0.9616898,
0.9618144, 0.961986, 0.9621864, 0.9623498, 0.9624878, 0.9626525,
0.9627835, 0.9628886, 0.9629866, 0.9631557, 0.9632875, 0.9634212,
0.9635417, 0.9636695, 0.9637814, 0.9638905, 0.9639689, 0.9640757,
0.964196, 0.9643034, 0.9644215, 0.9645278, 0.9646416, 0.9647334,
0.9648655, 0.9649719, 0.9650779, 0.9651884, 0.9653068, 0.9654192,
0.9655179, 0.9656188, 0.9657627, 0.965861, 0.9659789, 0.966077,
0.9661733, 0.966301, 0.9664198, 0.9664838, 0.9665656, 0.9666834,
0.9667807, 0.9668807, 0.9669509, 0.9670521, 0.9671343, 0.9672346,
0.967336, 0.9674322, 0.9675225, 0.9676096, 0.9677119, 0.9678031,
0.967893, 0.9679848, 0.9680899, 0.968179, 0.9682643, 0.9683379,
0.9684383, 0.9685187, 0.9686161, 0.9687164, 0.9688037, 0.9688999,
0.9689951, 0.9690893, 0.9691872, 0.9692667, 0.9693624, 0.9694321,
0.9695126, 0.9695981, 0.9696739, 0.9697611, 0.9698583, 0.9699427
), train_auc_4 = c(0.8719551, 0.8896184, 0.8948779, 0.898766,
0.9027315, 0.9049762, 0.9062427, 0.9073199, 0.9081683, 0.9092019,
0.9100824, 0.9109981, 0.9116318, 0.9123474, 0.9131612, 0.9138763,
0.9145007, 0.9152897, 0.9158685, 0.9166697, 0.9172174, 0.9179825,
0.9186526, 0.9193314, 0.9199804, 0.9205763, 0.9212371, 0.921792,
0.9223935, 0.9229936, 0.9234932, 0.9240162, 0.9245426, 0.9250783,
0.9256483, 0.9262044, 0.9267231, 0.9271653, 0.9276435, 0.9280976,
0.9284953, 0.9289266, 0.9293313, 0.9297668, 0.9301079, 0.9305796,
0.9309791, 0.9314001, 0.9317514, 0.932084, 0.9323953, 0.9326925,
0.9330121, 0.933329, 0.9335974, 0.9339083, 0.934189, 0.9344819,
0.934775, 0.9350779, 0.9353696, 0.9356319, 0.9358907, 0.9361598,
0.9364136, 0.936647, 0.9368967, 0.9370801, 0.9373547, 0.9375985,
0.9378257, 0.9380637, 0.9382862, 0.9385131, 0.9387194, 0.9389419,
0.9391624, 0.9393709, 0.939553, 0.9397668, 0.9399806, 0.9401861,
0.9403382, 0.9404968, 0.9406843, 0.9408617, 0.9410371, 0.9412126,
0.9413865, 0.9415654, 0.9417246, 0.9418873, 0.9420531, 0.9422337,
0.9423998, 0.9425335, 0.9426956, 0.9428642, 0.9429921, 0.9431463
), train_auc_5 = c(0.8894875, 0.9047447, 0.9105668, 0.9144695,
0.9172043, 0.9185459, 0.919896, 0.9209646, 0.9220889, 0.9229307,
0.923797, 0.9245408, 0.9252745, 0.9258488, 0.9264725, 0.9270811,
0.927705, 0.9283463, 0.9288456, 0.9293815, 0.9299636, 0.9305526,
0.9311112, 0.9317484, 0.9323305, 0.9328307, 0.9332667, 0.9338263,
0.9343498, 0.9348398, 0.9353667, 0.9358599, 0.9362733, 0.9367398,
0.9371676, 0.9376035, 0.9380137, 0.93843, 0.9388201, 0.9392386,
0.9396649, 0.9400335, 0.940358, 0.940702, 0.9410648, 0.9414072,
0.9417623, 0.9421251, 0.9424502, 0.9428179, 0.9431571, 0.9434742,
0.9438279, 0.9441624, 0.9444683, 0.944784, 0.9450568, 0.9453451,
0.9456379, 0.9459065, 0.9462062, 0.9464493, 0.9467355, 0.9469841,
0.9472465, 0.9475116, 0.9477762, 0.948027, 0.9482639, 0.9485123,
0.9487707, 0.9489929, 0.9492213, 0.9494459, 0.9497089, 0.9499556,
0.9501546, 0.9503753, 0.9505703, 0.9507616, 0.9509694, 0.9511743,
0.9513489, 0.9515396, 0.9517049, 0.9518854, 0.9520863, 0.9522618,
0.9524513, 0.9526601, 0.9528238, 0.9530262, 0.953238, 0.9534353,
0.9535989, 0.9537715, 0.953945, 0.9541034, 0.9542643, 0.9544374
), train_auc_6 = c(0.921898, 0.9414678, 0.9480329, 0.9519876,
0.9548386, 0.9567495, 0.9580347, 0.959306, 0.9603841, 0.9614684,
0.9623793, 0.9630147, 0.9637751, 0.964326, 0.9648042, 0.9653413,
0.9658432, 0.9664368, 0.9670508, 0.9675288, 0.9681021, 0.9685874,
0.969052, 0.9695682, 0.9699854, 0.9704805, 0.9708863, 0.97131,
0.9717166, 0.9721004, 0.9724803, 0.9728962, 0.9732809, 0.9736517,
0.9740503, 0.9744405, 0.974781, 0.9751438, 0.9754958, 0.9758019,
0.9761391, 0.9764902, 0.9768141, 0.9771417, 0.9774458, 0.9777964,
0.9780874, 0.9783719, 0.9786893, 0.9789502, 0.9792233, 0.9794795,
0.979716, 0.9799766, 0.9802053, 0.9804437, 0.9806533, 0.9808698,
0.9810933, 0.9813374, 0.9815627, 0.9817506, 0.9819429, 0.9821263,
0.9823146, 0.9824981, 0.9826867, 0.9828871, 0.9830589, 0.9832092,
0.9833926, 0.983539, 0.983694, 0.9838324, 0.9839557, 0.9841259,
0.9843032, 0.9844521, 0.9845934, 0.9847127, 0.9848563, 0.9849894,
0.9851023, 0.9852643, 0.9853757, 0.9854869, 0.9856046, 0.9857333,
0.9858394, 0.9859424, 0.9860531, 0.9861587, 0.986294, 0.9864175,
0.9865295, 0.9866261, 0.9867294, 0.986843, 0.9869372, 0.9870544
), train_auc_7 = c(0.8714998, 0.8904612, 0.8996561, 0.9041253,
0.9066398, 0.9086743, 0.910345, 0.9116165, 0.9130665, 0.914957,
0.9166201, 0.9180005, 0.9195517, 0.9207296, 0.9218763, 0.9230211,
0.9241087, 0.9252396, 0.9262592, 0.9271692, 0.9280938, 0.9289803,
0.9297884, 0.9305648, 0.9311738, 0.9317921, 0.9323804, 0.9329845,
0.933683, 0.9341942, 0.9347607, 0.9352553, 0.9357764, 0.9363214,
0.9367976, 0.9372965, 0.9377839, 0.9382045, 0.9386436, 0.9391153,
0.939509, 0.9399301, 0.9402878, 0.9405964, 0.9409411, 0.9413296,
0.9416693, 0.9419742, 0.9423106, 0.9426316, 0.9428824, 0.94322,
0.9435017, 0.9438152, 0.9440885, 0.9443691, 0.9446256, 0.9449214,
0.9451091, 0.945326, 0.9456083, 0.9458252, 0.9460603, 0.94633,
0.946581, 0.9468279, 0.9470671, 0.9473089, 0.9474984, 0.9477469,
0.9479721, 0.9482038, 0.9484291, 0.9486507, 0.9488756, 0.9490827,
0.9492949, 0.9494745, 0.9497085, 0.9499118, 0.9501382, 0.9503468,
0.9505637, 0.9507583, 0.9509843, 0.9512342, 0.9514627, 0.9516457,
0.9518377, 0.9520731, 0.9522473, 0.9524432, 0.9526339, 0.9528058,
0.9529749, 0.9531575, 0.9533158, 0.953497, 0.953663, 0.9538312
), train_auc_8 = c(0.8894918, 0.906573, 0.9133049, 0.9168864,
0.9194233, 0.9219299, 0.9237789, 0.9252068, 0.9265656, 0.9281103,
0.929274, 0.9307909, 0.9317895, 0.9328411, 0.933978, 0.9349498,
0.9358906, 0.936782, 0.9376891, 0.9385461, 0.9393091, 0.9401118,
0.940883, 0.941568, 0.9421953, 0.9427495, 0.9434112, 0.9439894,
0.944666, 0.9452999, 0.9457854, 0.9463698, 0.9468706, 0.9473643,
0.947829, 0.9482811, 0.9487576, 0.9492046, 0.9496415, 0.9500149,
0.9504884, 0.9509045, 0.9512969, 0.951719, 0.95214, 0.9525265,
0.9528557, 0.9531854, 0.9535102, 0.9537721, 0.9541137, 0.9544496,
0.9548184, 0.9551027, 0.955434, 0.9557073, 0.955989, 0.9563086,
0.9565974, 0.9569073, 0.9571664, 0.9574366, 0.9577329, 0.9580357,
0.9582985, 0.9585633, 0.9587903, 0.9590735, 0.9593316, 0.9596137,
0.9598677, 0.9600993, 0.9602947, 0.9605253, 0.9607954, 0.9610258,
0.9612257, 0.9614929, 0.9617122, 0.9619397, 0.9622056, 0.9624263,
0.9626628, 0.9628691, 0.9631282, 0.9633603, 0.9635655, 0.9638023,
0.9640161, 0.9642836, 0.9644966, 0.9646435, 0.9648045, 0.964987,
0.9652297, 0.9654192, 0.9655976, 0.9657743, 0.965976, 0.9662169
), train_auc_9 = c(0.9195993, 0.9417172, 0.949147, 0.9537538,
0.9565765, 0.9589093, 0.9607099, 0.962332, 0.9639256, 0.9652906,
0.9664848, 0.9675891, 0.9685598, 0.9695702, 0.9705377, 0.9713772,
0.9722889, 0.9730441, 0.9738743, 0.9745701, 0.9752537, 0.9759395,
0.9765657, 0.9772191, 0.9778215, 0.9783909, 0.9789667, 0.979504,
0.9799884, 0.9804533, 0.9808872, 0.9813206, 0.981738, 0.982081,
0.9824229, 0.9827401, 0.983044, 0.9833385, 0.9836874, 0.9840525,
0.9843545, 0.9845821, 0.984868, 0.985124, 0.9853725, 0.9855741,
0.9857704, 0.9860043, 0.986215, 0.9864325, 0.9865974, 0.9867876,
0.9870471, 0.9872346, 0.987455, 0.9877028, 0.9879157, 0.9880718,
0.9882622, 0.9884967, 0.9886666, 0.9888404, 0.9890087, 0.9891979,
0.9893628, 0.9895276, 0.9896856, 0.989821, 0.9899959, 0.9901792,
0.9903423, 0.9905105, 0.9906635, 0.9908151, 0.99095, 0.991091,
0.9912231, 0.9913755, 0.9914875, 0.9916226, 0.991765, 0.9919017,
0.9920161, 0.9921698, 0.9923023, 0.9924097, 0.9925314, 0.9926483,
0.9927896, 0.992922, 0.9930381, 0.9931279, 0.9932223, 0.9933255,
0.9934563, 0.99354, 0.9936327, 0.9937486, 0.9938403, 0.9939489
), ID = 1:100), .Names = c("train_auc_1", "train_auc_2", "train_auc_3",
"train_auc_4", "train_auc_5", "train_auc_6", "train_auc_7", "train_auc_8",
"train_auc_9", "ID"), row.names = c(NA, -100L), class = "data.frame")
答案 0 :(得分:3)
这是一种方法。请注意,我重塑数据以充分利用绘图美学:
library(tidyr)
library(ggplot2)
# reshape the data
df %>%
gather(trainauc, value, -ID) -> df
# get the order
df %>%
filter(ID == 100) %>%
arrange(desc(value)) %>%
.$trainauc -> leg_order
# plot
ggplot(df, aes(ID)) +
geom_line(aes(y = value, colour = trainauc)) +
scale_colour_discrete(breaks = leg_order) +
labs(title = "auc curves", y = "auc result", x = "rounds") +
theme_bw(base_size = 11, base_family = "") +