ggplot error - Melt

I am trying to use ggplot (melt) to plot the graph code R below. I am getting a strange looking graph an error message "No id variables; using all as measure variables" Any ideas please?

ggplot(data = melt(prediction[91:180]), aes(x = variable, y = value)) +
  geom_boxplot(aes(fill = variable)) +
  geom_point(data = ground_truth[91:180,], colour = 'red', aes(colour = "red")) +
  theme(legend.position = "none")

Hard to tell what to suggest -- could you give post the output of prediction[91:96] and similarly of ground_truth[91:96]? And could you describe what you had been hoping to see?

I am looking for a box plot which shows the ground truth against the predictions and where does each variable set in term of this in the graph.

prediction[91:96]

91        92        93        94        95        96
1   0.7362216 0.8781878 0.8719478 0.8427528 0.8724596 0.9466937
2   0.7207449 0.8856095 0.8848651 0.8702335 0.9021799 0.9035589
3   0.6545894 0.8349180 0.8273567 0.8036947 0.8367690 0.8618238
4   0.7581852 0.8754737 0.8702108 0.8525982 0.8755682 0.9057830
5   0.8115875 0.8977449 0.8914957 0.8709912 0.9039619 0.9519508
6   0.7284678 0.9027580 0.8957158 0.8711206 0.9022006 0.9424633
7   0.7097305 0.8456177 0.8310531 0.7944343 0.8414695 0.9303210
8   0.8131204 0.8777283 0.8654417 0.8435191 0.8808703 0.9331881
9   0.7525641 0.8002461 0.7946695 0.7724423 0.8096622 0.8981219
10  0.6853206 0.8694516 0.8635761 0.8382098 0.8658443 0.9108843
11  0.6384780 0.8128500 0.8151053 0.7960764 0.8241945 0.8507690
12  0.8116765 0.8588267 0.8554530 0.8414435 0.8620111 0.9115975
13  0.7901175 0.9210752 0.9107770 0.8903497 0.9242342 0.9464427
14  0.6956121 0.8678641 0.8564768 0.8260818 0.8738068 0.9249641
15  0.7003837 0.8909959 0.8862898 0.8620936 0.8889898 0.9303448
16  0.7566449 0.8165959 0.8161756 0.7969461 0.8479338 0.9138633
17  0.6649746 0.8428608 0.8355964 0.8014901 0.8424077 0.9242421
18  0.7262573 0.8443429 0.8415107 0.8185928 0.8401548 0.9088052
19  0.8153257 0.8376001 0.8455070 0.8342194 0.8700189 0.9320707
20  0.7569030 0.8752583 0.8681946 0.8444472 0.8712371 0.9290728
21  0.8328729 0.8708465 0.8630003 0.8465400 0.8750983 0.9273635
22  0.5938757 0.8413632 0.8404131 0.8168904 0.8364911 0.8557466
23  0.7507347 0.9048888 0.9007600 0.8849546 0.9047042 0.9151214
24  0.6341276 0.8360364 0.8401977 0.8222752 0.8394152 0.8579015
25  0.7450425 0.8585834 0.8540729 0.8318459 0.8538746 0.9155482
26  0.6951107 0.8249067 0.8197154 0.7911348 0.8193582 0.9060496
27  0.7316249 0.8422015 0.8302797 0.8100184 0.8455564 0.8706651
28  0.7749267 0.8250575 0.8098010 0.7859560 0.8247078 0.8963621
29  0.7583067 0.8080219 0.8085910 0.7967851 0.8227333 0.8673835
30  0.7711514 0.8383325 0.8358494 0.8189419 0.8358869 0.8977629
31  0.6943266 0.7065563 0.6991761 0.6768556 0.7101333 0.8339947
32  0.7539818 0.8696266 0.8726389 0.8693778 0.8920890 0.8351578
33  0.6492410 0.8406296 0.8414094 0.8118440 0.8296169 0.9160263
34  0.6688464 0.9255134 0.9209697 0.9028250 0.9239112 0.9195367
35  0.7299472 0.8458094 0.8421453 0.8170705 0.8468971 0.9208199
36  0.7253292 0.8490590 0.8428664 0.8172768 0.8482991 0.9155952
37  0.7945935 0.8348659 0.8331010 0.8172127 0.8497054 0.9128805
38  0.7893090 0.8261342 0.8280647 0.8154205 0.8536856 0.9063604
39  0.6269539 0.7989391 0.8008273 0.7665963 0.7934520 0.9095724
40  0.7103818 0.8376357 0.8321369 0.8074425 0.8450394 0.9051390
41  0.6081272 0.8161354 0.8172366 0.7910364 0.8086036 0.8686294
42  0.7049171 0.8558463 0.8594711 0.8447437 0.8702451 0.8897373
43  0.7896598 0.8020414 0.8083444 0.7896942 0.8003486 0.9226237
44  0.7735054 0.8295000 0.8230087 0.8038752 0.8281651 0.8967004
45  0.7988226 0.8334361 0.8336924 0.8205137 0.8594334 0.9116090
46  0.7575061 0.8859070 0.8813712 0.8587983 0.8929272 0.9415862
47  0.8098694 0.8185197 0.8124811 0.7946750 0.8256684 0.9109410
48  0.5820910 0.8765684 0.8751122 0.8516027 0.8680726 0.8783092
49  0.7666603 0.8976039 0.8939923 0.8767304 0.9034595 0.9299203
50  0.7860910 0.8879457 0.8836338 0.8665837 0.8840700 0.9231806
51  0.7862274 0.8901260 0.8893487 0.8786554 0.9093401 0.9118850
52  0.7730170 0.9242896 0.9210947 0.9099152 0.9298885 0.9158333
53  0.6623262 0.8373646 0.8355777 0.8174345 0.8560919 0.8624520
54  0.7370209 0.8462988 0.8330201 0.8045270 0.8523432 0.9158932
55  0.6134323 0.8330902 0.8263431 0.7869245 0.8222193 0.9207135
56  0.6822205 0.8843948 0.8818246 0.8613973 0.8841879 0.9065536
57  0.5835281 0.8333875 0.8229232 0.7939854 0.8328030 0.8461078
58  0.6825276 0.8397913 0.8368231 0.8166884 0.8382686 0.8709131
59  0.5991182 0.8728670 0.8705457 0.8447161 0.8730570 0.8987125
60  0.6297214 0.8184116 0.8253675 0.8051489 0.8170163 0.8668156
61  0.7741942 0.8540168 0.8479596 0.8341883 0.8654432 0.8836009
62  0.7601592 0.8476277 0.8487670 0.8334845 0.8519669 0.9012401
63  0.6625512 0.9247969 0.9229485 0.9016995 0.9275631 0.9499113
64  0.5936906 0.8349223 0.8256687 0.7927573 0.8294543 0.8788757
65  0.6654797 0.8587957 0.8542399 0.8302491 0.8540648 0.8917174
66  0.7507688 0.8511778 0.8462529 0.8275216 0.8572664 0.9001921
67  0.7248565 0.8382096 0.8353900 0.8113571 0.8401902 0.9130778
68  0.7321066 0.8680016 0.8615020 0.8403503 0.8673369 0.9055251
69  0.6657095 0.8654934 0.8672579 0.8411274 0.8713985 0.9321916
70  0.6410534 0.8659316 0.8621494 0.8409968 0.8657954 0.8730815
71  0.6727668 0.8612114 0.8521939 0.8135722 0.8527250 0.9448939
72  0.7703191 0.8154741 0.8002133 0.7643359 0.8217953 0.9387000
73  0.6629346 0.8430829 0.8345493 0.8041404 0.8358300 0.9011445
74  0.7785122 0.8985882 0.8958234 0.8790521 0.9074992 0.9365028
75  0.6995697 0.8547911 0.8574729 0.8424813 0.8625203 0.8806748
76  0.8243545 0.8396544 0.8384581 0.8246466 0.8421096 0.9160651
77  0.8494271 0.8511850 0.8509187 0.8443310 0.8848922 0.9150481
78  0.6272707 0.8640078 0.8587050 0.8355494 0.8640844 0.8728677
79  0.8099158 0.8645840 0.8478530 0.8139099 0.8619302 0.9551376
80  0.7951288 0.8826492 0.8677635 0.8439898 0.8856006 0.9288802
81  0.7887440 0.8300923 0.8272305 0.8147680 0.8623765 0.8967333
82  0.7643875 0.8610534 0.8523483 0.8244856 0.8557402 0.9365222
83  0.7021489 0.8353928 0.8357610 0.8127045 0.8374810 0.9065632
84  0.7971659 0.7969770 0.7943942 0.7786379 0.8178097 0.9026154
85  0.6771417 0.8443568 0.8446891 0.8237079 0.8520318 0.8929046
86  0.7244263 0.8828751 0.8787124 0.8619920 0.8795266 0.8907025
87  0.7664292 0.8771091 0.8692561 0.8491383 0.8777095 0.9161616
88  0.7225974 0.9139424 0.9031619 0.8799336 0.9133508 0.9301342
89  0.6693684 0.8985216 0.8971846 0.8782325 0.8985606 0.9105050
90  0.6859582 0.8225737 0.8226608 0.7961354 0.8245048 0.9088261
91  0.6698425 0.8532948 0.8523305 0.8327048 0.8511291 0.8768783
92  0.7610318 0.9306831 0.9232906 0.9059026 0.9310056 0.9380911
93  0.8214622 0.8712518 0.8634845 0.8422072 0.8771984 0.9429099
94  0.8406107 0.8257830 0.8137240 0.7930877 0.8350722 0.9279903
95  0.6643272 0.8511462 0.8515631 0.8256888 0.8411473 0.9102474
96  0.7078656 0.9176401 0.9158505 0.9005446 0.9184294 0.9181084
97  0.7259684 0.8839844 0.8743141 0.8522796 0.8869882 0.9089234
98  0.6028714 0.9082497 0.9043372 0.8810033 0.9122918 0.9185857
99  0.5585117 0.7956818 0.7929808 0.7628279 0.7928985 0.8444947
100 0.5912113 0.7711113 0.7833081 0.7655995 0.7741993 0.8213163
101 0.7569750 0.8880476 0.8839115 0.8721209 0.8855595 0.8736554
102 0.6730895 0.8327169 0.8365304 0.8166184 0.8592055 0.8986865
103 0.8181646 0.9071375 0.9049190 0.8929447 0.9127672 0.9316305
104 0.7531520 0.8774065 0.8709327 0.8442358 0.8756101 0.9430633
105 0.7201679 0.8596438 0.8510874 0.8257338 0.8548499 0.9094043
106 0.6423711 0.8503624 0.8441528 0.8118301 0.8586194 0.9204600
107 0.6371167 0.8344570 0.8348853 0.8044888 0.8273515 0.9122792
108 0.6794720 0.7872914 0.7860543 0.7606133 0.7882732 0.8807715
109 0.6842232 0.8437914 0.8616632 0.8540114 0.8871653 0.8913961
110 0.6727949 0.8423493 0.8361808 0.8075064 0.8548627 0.9121190
111 0.8056574 0.9066963 0.9030037 0.8853692 0.9107338 0.9495251
112 0.8376585 0.8631560 0.8549158 0.8340012 0.8598532 0.9409688
113 0.6790888 0.7410196 0.7467332 0.7292118 0.7562761 0.8466989
114 0.7738596 0.8483519 0.8465366 0.8374183 0.8534785 0.8590483
115 0.6328644 0.8781151 0.8723422 0.8504828 0.8774322 0.8757503
116 0.7402286 0.8971822 0.8915829 0.8689467 0.8990180 0.9387626
117 0.6595717 0.8502524 0.8659496 0.8634672 0.9050413 0.8430570
118 0.7549767 0.8417662 0.8306722 0.8089193 0.8451954 0.8945873
119 0.7734300 0.8512154 0.8452432 0.8254303 0.8596135 0.9143892
120 0.7959665 0.8475915 0.8391694 0.8146982 0.8504032 0.9335747
121 0.7325328 0.8931901 0.8873197 0.8628434 0.8878893 0.9379275
122 0.7223141 0.8903174 0.8945367 0.8849054 0.8958224 0.8824657
123 0.8341086 0.8139484 0.8213940 0.8113031 0.8487553 0.9283178
124 0.8096166 0.8119750 0.8088486 0.7842387 0.8131896 0.9375681
125 0.7432422 0.7869596 0.7987801 0.7903691 0.7902477 0.8569009
126 0.7407891 0.8781592 0.8706292 0.8537006 0.8792727 0.8865244
127 0.7458572 0.8320267 0.8220199 0.7966963 0.8330632 0.9059461
128 0.7349183 0.8724324 0.8628328 0.8392593 0.8814866 0.9171782
129 0.6516027 0.8765917 0.8731333 0.8507494 0.8727927 0.8943404
130 0.7549255 0.8288170 0.8281103 0.8146695 0.8422751 0.8784588
131 0.7437711 0.8334135 0.8342097 0.8199172 0.8365243 0.8783933
132 0.6668970 0.8476427 0.8508306 0.8307677 0.8556985 0.8949900
133 0.6538223 0.7858037 0.7820808 0.7447053 0.7809559 0.9128925
134 0.7441609 0.8489676 0.8425954 0.8250890 0.8495008 0.8807279
135 0.7575381 0.8448078 0.8440933 0.8254196 0.8570765 0.9147626
136 0.8676156 0.8638413 0.8523319 0.8246157 0.8624234 0.9651731
137 0.7084331 0.8774802 0.8708223 0.8471594 0.8860589 0.9197063
138 0.6728601 0.8874784 0.8944165 0.8824375 0.9121397 0.9031660
139 0.6363639 0.8668448 0.8654069 0.8547950 0.8785231 0.7958477
140 0.7780037 0.8694437 0.8693171 0.8557155 0.8736951 0.9073054
141 0.7417557 0.8240495 0.8200524 0.7969415 0.8169114 0.9028268
142 0.7762547 0.8609975 0.8578514 0.8397613 0.8625558 0.9163035
143 0.6792935 0.7878524 0.7950906 0.7814552 0.7798311 0.8308941
144 0.8655066 0.8866018 0.8720703 0.8557356 0.8887812 0.9305488
145 0.7956281 0.8318581 0.8320443 0.8108807 0.8617838 0.9421754
146 0.6426322 0.8411418 0.8456322 0.8347811 0.8476468 0.8104398
147 0.7513426 0.8762374 0.8748492 0.8650213 0.8776866 0.8616739
148 0.7657978 0.8420037 0.8414295 0.8230049 0.8486623 0.9137664
149 0.7118774 0.8762361 0.8669130 0.8414172 0.8779449 0.9173872
150 0.7380998 0.8591653 0.8596757 0.8368064 0.8886817 0.9425603
151 0.7316349 0.8938635 0.8889920 0.8656595 0.8892775 0.9363426
152 0.6849864 0.8533992 0.8457521 0.8240615 0.8529271 0.8738018
153 0.8352584 0.9035902 0.8930215 0.8731627 0.9041329 0.9475061
154 0.6911305 0.8927676 0.8894366 0.8690902 0.8940594 0.9145631
155 0.7895821 0.9123386 0.9118532 0.8981438 0.9182611 0.9400088
156 0.8107447 0.8709205 0.8686716 0.8471666 0.8759453 0.9507777
157 0.6853329 0.7912816 0.7773267 0.7395526 0.7904832 0.9073552
158 0.7757668 0.8810717 0.8750379 0.8514401 0.8787435 0.9412218
159 0.6232713 0.7914490 0.7969112 0.7728074 0.8134305 0.8779254
160 0.7311658 0.7242678 0.7306306 0.7158080 0.7348870 0.8585539
161 0.7854437 0.8223491 0.8117224 0.7948397 0.8316302 0.8828697
162 0.6263426 0.8395013 0.8340758 0.8127561 0.8436439 0.8426638
163 0.6604259 0.8185334 0.8115769 0.7856365 0.8269426 0.8755261
164 0.7031102 0.8557757 0.8454799 0.8243184 0.8607533 0.8744456
165 0.6136978 0.8712075 0.8674477 0.8477277 0.8688742 0.8510387
166 0.7097295 0.8349037 0.8284832 0.7987382 0.8271736 0.9174177
   value variable
91     0       91
92     1       92
93     1       93
94     0       94
95     0       95
96     1       96

It looks like the issue may be that the 'variable' column in ground_truth may not be a factor. Could you try

ground_truth <-  ground_truth %>% mutate(variable = factor(variable))

before you run the ggplot() command?

P.S. The message you got is a warning, rather than an error: melt() will interpret each column as data unless you indicate which columns uniquely identify the cases represented in your table.

1 Like

Many Thanks! This has fixed the graph, but i still need to show the variables name, also a legend which describe them.

Remove this and the legend should appear:

+ theme(legend.position = "none")
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.