This question already has answers here:
How to resize the ClipPath area of SVG?
(2 answers)
masking image with CSS
(2 answers)
Closed 10 months ago.
I'm trying to figure out a way to use an SVG path to hide portions of divs via CSS. The current method I know is using the SVG to clip the entire div. I'm wondering if there's a way to use a mask instead.
My desired result would be to clip only a portion of the div. For the example I was working on, would be the right side of the div.
I've linked my attempts, but at best I can only get clipping to work.
JSFiddle link.
.st0{fill:#000;}
div {
height: 100px;
background: red;
margin-bottom: 20px;
}
.wide {
width: 80%;
}
.short {
width: 20%;
}
.mask {
clip-path: url(#clip);
}
<div class="mask wide"></div>
<div class="mask short"></div>
<svg viewBox="0 0 119.5 290.5">
<defs>
<clippath id="clip">
<path class="st0" d="M12.1,0l27.1,35.2L18.8,72.1l49.3,41.3L9.9,172.6c0,0,43.6,47.1,44.4,44.9c0.9-2.2,36,12.9,32,13.3
s-63.6,12-63.6,12s6.2,17.8,7.6,17.8c1.3,0,55.1,0.9,53.8,0c-1.3-0.9-47.6,17.3-47.6,17.3l-21.3,12.6h104.2V0H12.1z"/>
</clippath>
</defs>
</svg>
Browser support for CSS masks is patchy at present.
However, depending on your requirements, you may be able to use CSS blend modes instead – see the example below. I have yet to find detailed, precise, non-technical descriptions of each blend mode – the best I have found today is this. Some experimentation may be required.
body {
margin: 5vh 5vw;
font-family: sans-serif;
background: #ddd;
}
.background {
background-image: url("https://images.unsplash.com/photo-1531786343146-f297424a3171?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
height: 90vh;
position: relative;
}
.overlay {
position: absolute;
top: 5vh;
left: 5vw;
right: 5vw;
bottom: 5vh;
background-color: transparent;
transition: all 600ms cubic-bezier(0.68, -0.55, 0.265, 1.55);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.overlay-text {
font-size: 20pt;
color: white;
display: inline-block;
position: relative;
}
.overlay-shape {
fill: white;
}
.overlay:hover {
background-color: #ffffffee;
mix-blend-mode: lighten; /* the overlay is painted only in areas where it is lighter than its parent (the background) */
}
.overlay:hover .overlay-text {
color: black;
}
.overlay:hover .overlay-shape {
fill: black;
}
<section class="background">
<div class="overlay">
<h1 class="overlay-text">HOVER ME.</h1>
<svg viewBox="0 0 1642 1920" xmlns="http://www.w3.org/2000/svg">
<path class="overlay-shape" d="m8071 19178c-20-52-31-109-71-340-22-130-52-270-66-310-64-181-200-376-489-703-316-357-419-485-518-646-188-304-308-621-386-1014-69-348-73-782-11-1170 38-236 61-508 70-825 11-347 17-416 55-624 95-518 236-1077 390-1556 35-107 86-256 113-330 48-127 64-180 143-455 43-152 144-464 180-560 47-122 66-166 155-355 84-180 137-316 192-500 50-164 90-320 82-315-5 3-20 26-36 53-57 99-261 420-393 619-275 416-294 456-530 1118-16 44-79 224-141 400-100 287-224 625-300 820-15 39-39 99-53 135-103 265-311 724-439 969-295 565-575 943-883 1190-342 275-680 465-1095 614-158 57-278 92-571 166-481 121-711 237-930 471-62 66-114 118-116 116-2-1 30-120 71-262 116-403 173-647 212-906 34-231 29-755-12-1193-75-792 266-1701 914-2435 137-156 455-470 625-617 292-255 570-443 892-607 61-30 108-55 105-56-3 0-30 9-60 19-550 191-677 239-895 336-418 186-696 250-1085 249-293 0-459-28-761-128-74-24-188-58-254-76-252-66-318-90-665-238-289-122-420-176-514-208-99-34-359-88-695-144-162-28-296-52-298-54-8-8 104-44 202-65 154-33 221-84 580-445 272-274 440-436 550-530 167-142 583-395 960-582 377-186 570-254 920-324 88-17 237-49 330-71 168-38 174-39 520-54 525-23 1114-37 1255-30 69 4 168 16 220 26 52 11 127 27 165 35 209 43 587 152 790 229 228 86 282 111 725 338 135 69 310 154 390 190 146 65 340 141 345 135 4-3-81-75-210-177-84-66-297-210-377-253-79-44-267-129-362-164-97-37-356-114-380-114-14 0-212-66-331-110-111-41-359-167-498-253-76-47-242-160-370-250-268-189-323-225-582-372-347-196-532-331-710-516-130-135-210-243-342-464-337-566-707-1019-1100-1348-137-115-173-150-173-173 0-14 139 6 277 40 148 37 500 135 758 211 370 110 488 142 730 196 440 98 527 119 730 170 677 171 991 284 1252 454 97 63 157 113 343 285 69 64 179 162 245 220 159 138 438 418 502 504 108 146 152 240 301 641 87 235 258 795 343 1122 12 46 23 83 26 83 2 0 3-593 2-1317-3-1656 6-2409 36-3133 58-1347 59-1395 60-2195 0-831 0-839-51-1090-44-215-64-358-64-453 0-120 14-153 84-193 54-31 97-36 143-18 15 6 51 11 80 10 65-2 107 18 122 59 8 23 5 125-9 393-38 710-50 1019-60 1527-19 989-32 1309-85 2112-41 606-50 953-65 2398-6 553-15 1156-20 1340s-9 358-9 385v50l24-85c117-421 505-1058 909-1490 291-311 669-585 1091-790 180-87 358-155 705-268 431-140 614-217 805-338 200-126 328-165 886-268 135-26 293-59 350-75 301-85 594-219 990-452 64-38 119-69 123-69 36 0-126 285-407 714-106 161-193 311-294 505-194 370-240 452-349 616-185 281-327 428-562 581-81 53-243 169-360 258-278 210-469 347-595 426-214 135-476 255-689 316-54 15-96 29-94 31s48-7 102-21c170-42 351-51 1019-51 673 0 689 1 1039 65 577 105 757 158 1147 336 267 121 696 354 877 476 154 104 304 234 672 587 262 251 326 308 433 385 83 59 101 66 236 91 46 9 102 23 124 32 51 21 43 24-118 53-166 29-526 104-666 139-141 35-228 69-569 223-456 206-488 219-756 298-72 21-164 50-205 65-270 98-482 147-714 166-372 30-761-42-1180-218-71-30-179-73-240-95-60-22-145-52-187-68-43-15-78-26-78-24 0 1 48 36 108 76 265 180 538 430 723 663 53 66 149 197 214 290 136 196 235 329 350 470 204 251 326 431 410 610 102 217 166 463 185 718 21 279 39 385 89 540 94 293 141 532 151 772 5 105 17 261 29 347 17 136 26 174 72 295 69 185 154 377 246 553 80 154 141 250 254 395 64 83 117 171 107 180-2 2-62-30-133-72-328-191-679-380-800-432-98-41-259-89-630-186-465-122-519-140-845-283-74-32-153-65-175-72-284-91-559-238-790-420-123-97-350-332-449-465-136-185-215-317-362-610-132-262-222-432-289-545-18-30-89-149-157-265-307-516-444-777-548-1040-66-165-149-340-230-480-35-60-81-141-103-180-137-238-223-478-307-860-103-469-163-659-253-809-39-65-201-267-261-326-39-37-49-43-64-33-9 6-16 15-15 20 2 9 509 1275 568 1418 21 50 48 116 61 148 13 31 35 83 48 115 13 31 40 95 61 142 181 416 268 691 385 1220 72 324 109 456 235 835 163 490 232 823 266 1270 14 190 21 1674 8 1845-33 462-221 862-615 1311-56 64-239 253-405 420-527 529-566 593-668 1093-21 102-41 189-44 192-4 4-11-5-16-18zm-2212-9354c134-49 153-57 546-215 193-77 370-149 395-159 25-9 86-34 135-55 552-228 885-353 984-370 38-6 41-9 41-40 0-38-12-45-74-45-55 0-241 34-389 71-211 53-359 122-527 247-225 167-332 221-685 350-60 22-146 56-190 75-85 36-356 177-341 177 4 0 52-16 105-36zm3576-403c-29-27-323-243-400-294-215-141-397-197-646-197h-116l-7 32c-11 56 34 98 189 175 211 106 493 194 865 271 112 23 127 25 115 13zm-948-666c274-56 532-161 923-375 139-76 273-139 439-207 152-61 477-171 589-198 40-9 71-20 68-22-3-3-78 11-168 31s-257 56-373 81c-262 57-467 114-604 167-58 23-270 123-471 223-414 206-468 230-571 247-85 13-101 23-88 56 7 19 15 22 70 22 34 0 118-11 186-25z" transform="matrix(.1 0 0 -.1 0 1920)"/>
</svg>
</div>
</section>
Credits: code image
Related
Minimal example on codepen
I made a header for my website, and in mobile view I have a hamburger icon that shows the nav when clicked.
I positioned this icon to be aligned with the logo. When I click on the logo, the header resizes in order to show the nav, but I don't want my icon to move. Unfortunately, I set its position (absolute) to top: 50% ; transform: translateY(-50%); to center it and it follows the height change of its parent.
Is there any way to make it sticky to its position in pure CSS? With Js I can calculate the coordinates of the logo and set the top property with this value, but I don't really want to use Js for this.
$(document).ready(function() {
$('#hamburger').click(function(){
$('#hamburger').toggleClass('active');
$('#hamburger_icon').toggleClass('active');
$('#nav').toggleClass('active');
});
});
body {
padding: 0px;
margin: 0px;
}
a {
text-decoration: none;
color: inherit;
}
ul {
padding: 0px;
margin: 0px;
}
header {
position: relative;
padding-left: 0px;
padding-right: 0px;
width: 100%;
box-sizing: border-box;
background-color: white;
box-shadow: 0 3px 28px rgba(0, 0, 0, 0.15);
}
header div {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
header div svg {
margin-top: 0.5em;
margin-bottom: 0.5em;
height: 50px;
position: relative;
}
header div ul {
list-style: none;
text-decoration: none;
display: flex;
font-size: 0.8em;
max-height: 0px;
overflow: hidden;
transition: all ease-out 0.2s;
}
header div ul.active {
max-height: 200px;
margin-top: 0.6em;
margin-bottom: 0.6em;
}
header div ul li {
margin-right: 1em;
margin-left: 1em;
position: relative;
}
header #hamburger {
top: 50%;
transform: translateY(-50%);
right: 2.5em;
position: absolute;
height: 1.6em;
width: 1.6em;
padding: 0.2em;
}
header #hamburger #hamburger_icon {
top: 50%;
transform: translateY(-50%);
position: relative;
display: block;
background-color: black;
height: 0.1em;
width: 100%;
border-radius: 1.5px;
transition: all ease-out 0.2s;
}
header #hamburger #hamburger_icon::before, header #hamburger #hamburger_icon::after {
content: "";
display: block;
background-color: black;
height: 0.1em;
width: 100%;
border-radius: 1.5px;
transition: all ease-out 0.2s;
position: absolute;
}
header #hamburger #hamburger_icon::before {
top: -0.4em;
}
header #hamburger #hamburger_icon::after {
top: 0.4em;
}
header #hamburger #hamburger_icon.active {
transform: rotate(90deg);
}
header #hamburger #hamburger_icon.active::before, header #hamburger #hamburger_icon.active::after {
width: 40%;
}
header #hamburger #hamburger_icon.active::before {
transform: rotate(-45deg);
top: -0.25em;
}
header #hamburger #hamburger_icon.active::after {
transform: rotate(45deg);
top: 0.25em;
}
#main_logo {
fill: black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
<div class="header_content">
<svg class="flex_elem" id="main_logo" version="1.0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1733.000000 1964.000000" preserveAspectRatio="xMidYMid meet">
<g id="the_logo" transform="translate(0.000000,1964.000000) scale(0.100000,-0.100000)" stroke="none">
<path d="M8530 19634 c-148 -23 -272 -60 -380 -114 -97 -48 -7567 -4361 -7644 -4413 -32 -22 -92 -72 -134 -111 -209 -197 -336 -464 -362 -760 -13 -152 -13 -8680 0 -8832 26 -297 153 -562 362 -760 42 -39 102 -90 135 -112 110 -75 7618 -4405 7693 -4437 304 -130 662 -126 955 9 39 18 994 565 2121 1216 1127 650 2144 1237 2259 1303 116 66 224 130 242 143 39 30 68 100 60 150 -7 41 -517 934 -558 976 -32 32 -96 53 -141 44 -18 -3 -121 -57 -228 -119 -1511 -877 -4229 -2441 -4241 -2441 -9 -1 -1661 949 -3672 2109 l-3656 2110 0 4225 0 4225 3627 2093 c1995 1151 3643 2103 3664 2114 l36 21 3661 -2114 3661 -2113 0 -3683 0 -3683 -22 -4 c-36 -8 -4419 -417 -4459 -416 -43 0 -96 33 -121 75 -14 25 -89 788 -447 4590 -237 2508 -436 4580 -441 4605 -32 135 -169 240 -312 240 -27 0 -286 -22 -576 -50 -520 -49 -528 -50 -589 -80 -34 -17 -76 -47 -94 -67 -44 -51 -80 -132 -85 -195 -2 -30 220 -2422 499 -5374 471 -4974 505 -5324 525 -5357 27 -42 75 -67 132 -67 92 0 6739 630 6800 645 138 33 290 127 375 233 60 74 122 202 140 288 13 60 15 632 15 4276 0 2940 -3 4230 -11 4284 -44 321 -236 630 -499 806 -83 55 -7533 4359 -7638 4412 -81 41 -218 84 -322 101 -86 13 -265 18 -330 9z"/>
<path d="M6340 15539 c-639 -47 -1156 -179 -1531 -391 -608 -343 -907 -961 -989 -2048 -18 -234 -24 -904 -11 -1270 49 -1417 248 -3459 462 -4735 145 -867 296 -1410 509 -1836 293 -584 673 -894 1252 -1023 393 -87 922 -95 1468 -20 272 37 631 120 881 204 263 89 340 135 354 213 3 18 -19 287 -49 599 -59 617 -58 613 -122 650 -49 28 -96 25 -284 -19 -673 -160 -1283 -194 -1618 -92 -415 128 -606 509 -766 1529 -134 852 -337 2837 -426 4170 -78 1168 -59 1639 80 1998 103 267 305 417 690 513 280 69 560 92 1075 87 363 -3 393 -2 418 15 43 28 67 75 67 132 0 28 -23 295 -51 595 -55 587 -56 595 -117 636 -51 35 -291 74 -582 94 -165 11 -554 11 -710 -1z"/>
</g>
</svg>
<ul class="flex_elem" id="nav">
<li class="nav-item"> <a class="nav-link menu_link" href="#">ITEM1</a> </li>
<li class="nav-item"> <a class="nav-link menu_link" href="#">ITEM2</a> </li>
<li class="nav-item"> <a class="nav-link menu_link" href="#">ITEM3</a> </li>
<li class="nav-item"> <a class="nav-link menu_link" href="#">ITEM4</a> </li>
</ul>
</div>
<div id="hamburger">
<div id="hamburger_icon"></div>
</div>
</header>
</body>
Try just to modify this, within #hamburger_icon, adding top attribute:
&.active {
transform: rotate(90deg);
top: 0;
}
I have some data taken from a moving instrument through the water and flow data were logged every 0.5 seconds.I need to make a graph showing flow along the path of the instrument with different colors for selected range of flow (lets say 0.1 -1.5) and all outliers in same color.
How can I use R to plot the graph?
Here's some of my data:
idNr flow dep
21 0.135714532 3.16
22 0.131061729 3.07
23 0.13299406 3.11
24 0.145316675 3.1
25 6.31297442 3.07
26 0.331310509 3.14
27 0.445034592 3.17
28 0.637348777 3.45
29 0.87382414 4.04
30 1.302061623 5.31
31 1.80235436 6.78
32 1.63399146 8.24
33 1.675284308 9.78
34 1.686855996 11.27
35 1.775785232 12.72
36 1.455096956 14.22
37 1.530298919 15.69
38 1.431618958 17.15
39 1.446519477 18.7
40 1.532840436 20.15
41 1.595988278 21.55
42 1.478074882 23.07
43 1.545724299 24.5
44 1.475195233 26.05
45 1.542920138 27.56
46 1.437394899 29.02
47 1.644596033 30.59
48 2.303170426 31.94
49 1.77077097 33.5
50 1.530637295 34.97
51 1.439630621 36.41
52 1.469339767 37.9
53 1.330177211 39.36
54 1.478639264 40.85
55 1.465239548 42.3
56 1.536369473 43.85
57 1.484045946 45.39
58 1.561566967 46.92
59 1.487268243 48.5
60 1.509553327 50.01
61 1.436443415 51.42
62 1.520071435 52.98
63 1.455013499 54.55
64 1.472445826 56.01
65 1.499715554 57.48
66 1.514167783 58.99
67 1.493601132 60.62
68 1.531585488 62.05
69 1.625335896 63.61
70 1.478178989 65.08
71 1.531871974 66.57
72 1.472113782 68.16
73 1.4799859 69.58
74 1.458177137 71.21
75 1.591356624 72.79
76 1.542120401 74.28
77 1.694959183 75.77
78 1.720245831 77.25
79 1.519968728 78.75
80 1.390172108 80.34
81 1.520286586 81.81
82 1.592769579 83.38
83 1.632539512 84.88
84 1.481495103 86.41
85 1.529086844 87.98
86 1.536760058 89.52
87 1.52298084 91.03
88 1.731281442 92.53
89 1.639074839 94.02
90 1.562987505 95.53
91 1.543290194 97.04
92 1.578430537 98.61
93 1.702396728 100.12
94 1.657955781 101.6
95 1.557872012 103.16
96 1.613944568 104.68
97 1.631505361 106.16
98 1.435526209 107.66
99 1.711407354 109.26
100 1.57266259 110.72
101 1.514305998 112.27
102 1.56082106 113.78
103 1.828251113 115.27
104 1.748255115 116.76
105 1.854233769 118.3
106 1.803737202 119.75
107 1.67996921 121.25
108 1.751109178 122.77
109 1.76849805 124.32
110 1.758307258 125.82
111 1.740444751 127.32
112 1.644748694 128.81
113 1.620253049 130.29
114 1.75889143 131.77
115 1.760015837 133.24
116 1.683797088 134.78
117 1.713609054 136.31
118 1.26352548 137.78
119 1.81112139 139.37
120 1.888694446 140.83
121 1.774687553 142.36
122 1.739557437 143.78
123 1.64517875 145.33
124 1.699596858 146.8
125 1.628577412 148.35
126 1.769012673 149.81
127 1.594415839 151.41
128 1.493148224 152.89
129 1.581041449 154.42
130 1.538720671 155.93
131 1.589420092 157.41
132 1.64016166 158.93
133 1.575397227 160.43
134 1.63183131 162
135 1.75038462 163.44
136 1.434958447 165.01
137 1.74120127 166.5
138 1.748106592 167.98
139 1.813005453 169.46
140 1.541089106 170.98
141 1.556216895 172.56
142 1.660628956 174.08
143 1.693981673 175.61
144 1.67059241 177.09
145 1.66300418 178.66
146 1.652198157 180.17
147 1.709649777 181.65
148 1.745386082 183.15
149 1.385201724 184.62
150 1.468321001 186.15
151 1.627495534 187.58
152 1.678188454 189.03
153 1.810850273 190.55
154 1.585102162 192.01
155 1.652869637 193.48
156 1.593472296 195.03
157 1.846131262 196.53
158 1.442232687 198.03
159 1.279801142 199.57
160 1.803737202 201.06
161 1.794407014 202.61
162 1.456371696 204
163 1.815429315 205.38
164 1.518992563 206.89
165 1.647235482 208.41
166 1.47721908 209.86
167 1.698562049 211.35
168 0.835645183 211.94
169 0.971816361 211.79
170 0.215360462 212.01
171 0.576920795 212.05
172 0.504199289 212.02
173 0.352668234 212.02
174 0.503149022 211.89
175 0.180540198 212
176 0.242642996 211.91
177 0.132911363 211.98
178 0.131504237 212
179 0.131893716 211.96
180 0.132283195 211.9
181 0.132672674 212.02
182 0.919043761 212.02
183 1.705414848 211.94
184 2.491785935 211.9
185 0.187914127 211.97
186 0.137465923 211.98
187 0.490799032 211.85
188 0.695088396 211.6
189 0.283676082 211
190 0.965362936 210.07
191 0.769205485 209.16
192 1.41417407 208.1
193 1.437885765 207.08
194 1.359908615 206.02
195 1.311925665 204.77
196 1.239993728 203.57
197 1.352713698 202.38
198 1.454984487 201.12
199 1.07880741 199.89
200 1.171552813 198.65
201 1.32237999 197.41
202 1.354385018 196.15
203 1.090512744 194.97
204 1.390356612 193.71
205 1.213781005 192.33
206 1.431367612 191.08
207 1.384149391 189.81
208 1.282003839 188.57
209 1.332777243 187.45
210 1.235528323 186.19
211 1.110193788 184.9
212 1.247866678 183.7
213 1.193442015 182.56
214 1.313545026 181.36
215 1.284521151 180.08
216 1.258253835 178.91
217 1.263683914 177.68
218 1.331011134 176.49
219 1.234639947 175.26
220 1.338309201 174.07
221 1.224766564 172.91
222 1.280519417 171.66
223 1.150706617 170.44
224 1.260841259 169.25
225 1.09289038 168.05
226 1.262740102 166.84
227 1.170657422 165.68
228 1.176689196 164.49
229 1.262806038 163.31
230 1.40733017 162.17
231 1.24825008 160.93
232 1.282003839 159.8
233 1.237756113 158.62
234 1.339447054 157.48
235 1.383181118 156.3
236 1.213781005 155.12
237 1.310221259 154.01
238 1.344108343 152.81
239 1.367520862 151.66
240 1.197841162 150.49
241 1.219617617 149.28
242 1.299869434 148.11
243 1.370740857 146.95
244 1.175491535 145.83
245 1.272503374 144.68
246 1.251364988 143.52
247 1.321138129 142.3
248 1.127328278 141.16
249 1.319040773 139.94
250 1.118599826 138.74
251 1.312986113 137.64
252 1.392439005 136.41
253 1.197514718 135.29
254 1.218054343 134.14
255 1.230533733 132.94
256 1.209399639 131.82
257 1.362942371 130.63
258 1.365576729 129.47
259 1.235870422 128.24
260 1.250791647 127.08
261 1.407273491 125.89
262 1.279498015 124.77
263 1.419950309 123.67
264 1.343802584 122.51
265 1.359908615 121.28
266 1.221997022 120.16
267 1.406570776 118.98
268 1.32583614 117.77
269 1.456010534 116.59
270 1.446890774 115.47
271 1.486626504 114.25
272 1.271696732 113.07
273 1.123066893 111.94
Something like below?
# cut the flow data into range and add that into new "group" column
df$group <- cut(df$flow, c(0.1,1.5,max(df$flow)), labels=c("group1","group2"))
# plot the graph
library(ggplot2); library(dplyr)
ggplot(df, aes(x=idNr, y=flow)) +
geom_point(data = df %>% filter(group == "group1"), aes(colour=flow)) +
scale_colour_gradient(low="green", high="red", name="Not Outliers") +
geom_point(data = df %>% filter(group == "group2"), aes(size="Outliers"), colour="blue") +
guides(size = guide_legend("Outliers"))
Edit
per comment from OP.
If use dep as Y-axis, i.e. replace flow with dep in code (for ggplot) above,
graph will be
I have some data taken from a moving instrument through the water. The instrument moved in a zig zag way and flow data were logged every 0.5 seconds.
I need to make a graph showing flow along the path of the instrument with different colors for each flow value.
How can I use R to plot the graph?
Here's some of my data:
idNr flow dep
27 0.288261301 4.04
28 0.321201425 3.96
29 0.348002863 4.05
30 0.266207609 3.98
31 0.344623682 3.98
32 0.33590977 4.02
33 0.333196711 3.98
34 0.443371838 4.08
35 0.751650508 4.35
36 1.026660332 5.15
37 1.79303221 6.52
38 1.804413243 8.04
39 1.773816905 9.55
40 1.782303493 10.99
41 1.726813914 12.49
42 1.61061413 13.95
43 1.747734972 15.44
44 1.619344989 16.88
45 1.527087967 18.37
46 1.552443997 19.84
47 1.580849856 21.36
48 1.47038517 22.8
49 1.392708417 24.28
50 1.56442883 25.78
51 1.777948528 27.22
52 1.802147241 28.7
53 1.87299915 30.2
54 2.053852522 31.7
55 1.642625947 33.18
56 1.427217507 34.62
57 1.52030689 36.05
58 1.417431073 37.55
59 1.443192082 39.1
60 1.34374145 40.56
61 1.421155629 42.01
62 1.333494728 43.58
63 1.3194019 45.03
64 1.394158603 46.62
65 1.429844828 48.08
66 1.367911241 49.58
67 1.355840925 51.02
68 1.378465281 52.55
69 1.523250886 53.91
70 1.365535668 55.61
71 1.396372615 57.04
72 1.347452677 58.57
73 1.382778102 60.02
74 1.455112272 61.48
75 1.350807161 63.02
76 1.386283066 64.42
77 1.390035765 65.97
78 1.383424985 67.4
79 1.395385154 68.96
80 1.381371239 70.49
81 1.400707773 71.98
82 1.476066775 73.48
83 1.284056739 75.03
84 1.475329288 76.46
85 1.459387313 78.01
86 1.465585987 79.61
87 1.431249165 81.19
88 1.357601114 82.55
89 1.382301557 84.12
90 1.445689198 85.61
91 1.36922513 87.16
92 1.520221768 88.68
93 1.498713299 90.21
94 1.598120373 91.74
95 1.434218834 93.23
96 1.526169617 94.77
97 1.53240429 96.32
98 1.593795786 97.73
99 1.60067114 99.26
100 1.699682725 100.85
101 1.656267698 102.39
102 1.688246548 103.97
103 1.665317693 105.45
104 1.710451732 106.94
105 1.558604843 108.5
106 1.682163929 109.96
107 1.754686611 111.43
108 1.451731985 112.94
109 1.75889143 114.49
110 1.578577562 115.98
111 1.660725181 117.43
112 1.638376473 119.05
113 1.701685385 120.54
114 1.603928968 122.06
115 1.716673882 123.55
116 1.721613119 125.04
117 1.520097264 126.52
118 1.673504264 128.04
119 1.651535476 129.54
120 1.716307179 131.06
121 1.661417444 132.56
122 1.807044943 134.09
123 1.670927777 135.61
124 1.816092103 137.15
125 1.61581054 138.66
126 1.443289015 140.17
127 1.548887918 141.65
128 1.742922886 143.19
129 1.407817467 144.64
130 1.537282981 146.2
131 1.605707701 147.66
132 1.595514766 149.11
133 1.664969522 150.64
134 1.597832102 152.2
135 1.656365329 153.63
136 1.475701825 155.17
137 1.584298389 156.64
138 1.511851004 158.09
139 1.81195684 159.64
140 1.429699891 161.16
141 1.453907433 162.64
142 1.583450822 164.13
143 1.670092861 165.61
144 1.564082726 167.12
145 1.705749786 168.64
146 1.617373325 170.1
147 1.705749786 171.67
148 1.750116174 173.24
149 1.612112174 174.71
150 1.543739041 176.19
151 1.658449408 177.8
152 1.544094384 179.26
153 1.660865163 180.72
154 1.718616091 182.32
155 1.652198157 183.8
156 1.663230727 185.21
157 1.760015837 186.74
158 1.543345815 188.16
159 1.518992563 189.66
160 1.719743279 191.14
161 1.871325988 192.63
162 1.338309201 194.15
163 1.834802202 195.66
164 1.900303456 197.19
165 1.789994802 198.73
166 1.641265789 200.15
167 1.711407354 201.66
168 1.777665955 203.12
169 1.650013219 204.61
170 1.752274015 206.09
171 1.769734944 207.59
172 1.63480019 209.04
173 1.67727874 210.53
174 1.661860415 212.01
175 1.670834431 213.51
176 1.875008828 214.91
177 1.198086144 216.41
178 1.473233127 217.84
179 1.401750052 219.35
180 1.465064864 220.81
181 1.507361683 222.31
182 1.594120168 223.76
183 1.603827938 225.28
184 1.836556292 226.72
185 1.778422956 228.19
186 1.644971831 229.7
187 1.803737202 231.17
188 1.828251113 232.68
189 1.762103594 234.16
190 1.659823074 235.6
191 1.894313483 237.05
192 1.814170041 238.56
193 1.887235594 239.99
194 1.941720868 241.54
195 1.948726387 242.95
196 1.563589543 244.41
197 2.066101568 245.9
198 1.880538604 247.35
199 1.728849162 248.83
200 1.653487854 250.29
201 1.79743983 251.68
202 1.871167606 253.23
203 2.080688007 254.73
204 1.929135455 256.02
205 1.911069255 257.82
206 1.989423875 259.3
207 1.990416392 260.79
208 2.114887554 262.26
209 1.906502828 263.69
210 1.85085669 265.23
211 1.831357625 266.45
212 1.045764375 266.63
213 0.917485268 266.81
214 0.569920704 266.97
215 0.622531097 267.12
216 0.256491127 267.56
217 0.274736316 267.07
218 0.292981505 266.97
219 0.214553306 266.97
220 0.136125106 267.07
221 0.160799901 267.07
222 0.185474696 267.02
223 0.210149491 267.05
224 0.234824285 267.18
225 0.25949908 267.09
226 0.284173875 267.07
227 0.30884867 267.09
228 0.333523464 267.22
229 0.358198259 267.14
230 0.382873054 267.12
231 0.407547849 267.03
232 0.600179663 266.73
233 0.433797472 266.11
234 1.060132593 265.09
235 1.425310466 264.15
236 1.486875715 263.14
237 1.43689659 262.02
238 1.431465999 260.75
239 1.583936163 259.53
240 1.473233127 258.31
241 1.531834262 257.17
242 1.533104902 255.91
243 1.328999131 254.8
244 1.421761697 253.69
245 1.335436257 252.51
246 1.419856749 251.32
247 1.3703995 250.15
248 1.408783282 248.96
249 1.517088222 247.77
250 1.343802584 246.62
251 1.421537306 245.37
252 1.40061345 244.24
253 1.272161015 243.04
254 1.406138921 241.84
255 1.085843236 240.68
256 1.33602153 239.51
257 1.388280895 238.34
258 1.529552382 237.13
259 1.369493364 235.92
260 1.483642587 234.77
261 1.32851338 233.57
262 1.44039718 232.31
263 1.496418268 231.13
264 1.165322973 229.97
265 1.106764899 228.73
266 1.329991043 227.55
267 1.207740991 226.4
268 1.235528323 225.22
269 1.306827536 224.05
270 1.143623212 222.81
271 1.441714487 221.66
272 1.232362719 220.44
273 1.383297901 219.22
274 1.352388645 218.1
275 1.311460327 216.89
276 1.321217162 215.72
277 1.207279506 214.54
278 1.398024867 213.36
279 1.213781005 212.17
280 1.261582854 210.99
281 1.25985833 209.84
282 1.286305023 208.73
283 1.182046703 207.58
284 1.184988693 206.45
285 1.402951933 205.31
286 1.192968302 204.19
287 1.196836091 203.12
288 1.32083886 201.98
289 1.253255036 200.76
290 1.317613352 199.63
291 1.18891426 198.5
292 1.112625424 197.37
293 1.449004681 196.23
294 1.221578748 195.05
295 1.08139601 193.89
296 1.124301897 192.79
297 1.317373248 191.67
298 0.752773451 190.53
299 1.286574964 189.41
300 1.221500152 188.31
301 1.277374406 187.24
302 1.14505629 186.12
303 1.114030657 184.93
304 1.156791522 183.85
305 1.339019098 182.71
306 1.072565891 181.58
307 1.219754186 180.44
308 1.176963397 179.29
309 1.311925665 178.2
310 1.106051874 176.99
311 1.210041464 175.82
312 1.08161895 174.75
313 1.236070783 173.61
314 1.249614259 172.45
315 1.129300446 171.35
316 1.091558486 170.16
317 1.191516344 169.05
318 1.127521887 167.92
319 1.218621558 166.77
320 1.213781005 165.66
321 1.128293182 164.56
322 1.088186282 163.4
323 1.137727115 162.3
324 1.127388814 161.14
325 1.12490278 160.04
326 1.161036195 158.9
327 1.151329101 157.69
328 1.15757108 156.62
329 1.021796004 155.52
330 1.209076674 154.36
331 1.140870746 153.2
332 1.216107261 152.13
333 1.143405517 150.94
334 1.215779458 149.84
335 1.197327517 148.74
336 1.160052933 147.56
337 1.15880757 146.43
338 1.140225768 145.32
339 1.150143952 144.23
340 1.181602396 143.07
341 1.262274239 141.98
342 1.150799931 140.89
343 1.190711665 139.69
344 1.192584323 138.56
345 1.122635588 137.42
346 1.17500199 136.32
347 1.23807517 135.17
348 1.237353656 134.06
349 1.186746005 132.94
350 1.194924674 131.84
351 1.259003717 130.69
352 1.19677967 129.59
353 1.194242503 128.47
354 1.220205134 127.36
355 1.127990121 126.24
356 1.213781005 125.12
357 1.225973285 123.98
358 1.084756214 122.92
359 1.16161302 121.79
360 1.133334361 120.69
361 1.103127249 119.47
362 1.213781005 118.39
363 1.145836506 117.33
364 1.20781161 116.23
365 1.268126196 115.11
366 1.246070826 113.87
367 1.152060081 112.76
368 1.115006535 111.65
369 1.317280173 110.52
370 1.122671561 109.52
371 1.023553395 108.36
372 1.238632991 107.22
373 1.235124322 106.09
374 1.345223487 104.93
375 1.129630965 103.82
376 1.203403012 102.73
377 1.218779527 101.63
378 1.083551945 100.55
379 1.217290587 99.34
380 1.189233024 98.26
381 1.181995069 97.11
382 1.178651465 95.98
383 1.167093928 94.92
384 1.151487191 93.77
385 1.117688875 92.67
386 1.20046723 91.55
387 1.110913079 90.4
388 1.159221326 89.29
389 1.129196317 88.25
390 1.147979401 87.2
391 1.063138489 86.2
392 1.039855855 85.19
393 1.055872599 84.26
394 1.021566005 83.23
395 1.031262374 82.26
396 1.036922271 81.3
397 1.071390137 80.36
398 1.051908853 79.33
399 1.05363193 78.37
400 1.049712054 77.42
401 1.065736139 76.43
402 1.040108714 75.45
403 1.036886439 74.46
404 1.034880221 73.49
405 1.026660332 72.52
406 1.045490737 71.48
407 1.041245049 70.52
408 1.043207468 69.59
409 1.040543451 68.63
410 1.048860034 67.59
411 1.051861014 66.62
412 1.037198757 65.68
413 1.046622175 64.69
414 1.030435095 63.77
415 1.030156191 62.77
416 1.03762919 61.78
417 1.050493282 60.81
418 1.038155437 59.82
419 1.045090365 58.8
420 1.043834133 57.86
421 1.029653777 56.85
422 1.030381872 55.92
423 1.05024807 54.98
424 1.04567738 54.06
425 1.050961984 53.12
426 1.064207877 52.05
427 1.041433576 51.05
428 1.049447154 49.99
429 1.030094049 49.05
430 1.061292117 48.12
431 1.03820263 47.11
432 1.047136302 46.12
433 1.043207468 45.15
434 1.031741777 44.27
435 1.042840882 43.31
436 1.023755536 42.17
437 1.039746288 41.24
438 1.01600053 40.31
439 1.043669864 39.36
440 1.034305507 38.36
441 1.037222818 37.37
442 1.071353563 36.34
443 1.041574131 35.4
Not exactly what you were asking for, but this shows that the flows were distinctly lower as the device was ascending - something the colors don't really demonstrate IMO.
library(ggplot2)
data$direction <- with(data,ifelse(idNr<idNr[which.max(dep)],
"Descending","Ascending"))
ggplot(data,aes(x=dep,y=flow))+
geom_path(aes(color=direction))+
theme_bw()
One possible way (assuming I've got the x-axis & y-axis variables correct that that dep is "depth" - which is why I inverted the y-axis):
library(ggplot2)
gg <- ggplot(dat, aes(x=idNr, y=dep))
gg <- gg + geom_line(aes(color=flow), size=2)
gg <- gg + scale_y_reverse()
gg <- gg + scale_color_gradient(low="blue", high="red")
gg <- gg + theme_bw()
gg
Though you might be better of using cut to define discrete breaks (and, hence, colors) for the flow values rather than assign a continuous color range.
I am trying to read a few hundred html tables using readHTMLTable in R. This works mostly fine, expect for a couple of tables. The tables look fine in firefox.
Specifically, tables are by year and state. The following code reads the first table for Maryland in 2005 and works fine:
readHTMLTable("http://www.ssa.gov/policy/docs/statcomps/oasdi_sc/2005/md.html", header=FALSE)[[1]]
However, when trying to do this for Maryland and 2006, the table consists only of the first row of numbers.
readHTMLTable("http://www.ssa.gov/policy/docs/statcomps/oasdi_sc/2006/md.html", header=FALSE)[[1]]
I'm not sure where the problem is and appreciate if anyone could point me toward that.
Stephan
The problem I see is in the second URL "http://www.ssa.gov/policy/docs/statcomps/oasdi_sc/2006/md.html" if you inspect the source code you will see that in the "table 4" there is 2 "tbody". Then I think that readHTMLTable read the first tbody it founds in the page. Thats why you only get the "first" row (which is the first tbody tag)
You need to precise the tbody you want, in your case it's the 2nd tbody of the table in the div with the id "table4", you can identify this node by "//div[#id='table4']/table/tbody[2]"
doc <- "http://www.ssa.gov/policy/docs/statcomps/oasdi_sc/2006/md.html"
body <- getNodeSet(htmlParse(doc), "//div[#id='table4']/table/tbody[2]")[[1]]
> readHTMLTable(body)
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12
1 Allegany 16,515 10,060 1,060 120 1,955 560 2,225 75 460 4,835 7,050
2 Anne Arundel 69,550 47,150 3,245 475 6,380 2,750 7,760 100 1,690 21,900 29,260
3 Baltimore 136,035 91,755 6,040 1,200 13,470 5,545 14,695 175 3,155 41,480 61,215
4 Calvert 10,655 7,035 450 95 1,035 520 1,195 20 305 3,225 4,330
5 Caroline 5,955 3,835 180 70 575 245 835 10 205 1,760 2,355
6 Carroll 24,835 17,205 1,030 160 2,270 825 2,675 30 640 7,635 10,880
7 Cecil 15,030 8,870 630 140 1,415 725 2,435 55 760 4,210 5,330
8 Charles 14,925 9,305 625 135 1,320 950 2,040 20 530 4,275 5,625
9 Dorchester 6,980 4,860 165 65 550 265 895 10 170 2,105 2,875
10 Frederick 28,270 18,950 1,300 225 2,585 1,025 3,205 40 940 8,550 12,080
11 Garrett 6,300 3,760 435 45 780 225 855 40 160 1,910 2,485
12 Harford 34,695 23,020 1,540 235 3,330 1,365 4,140 60 1,005 10,540 14,330
13 Howard 26,855 18,825 1,150 260 2,085 1,275 2,555 25 680 8,595 11,330
14 Kent 5,385 3,865 280 40 485 125 500 5 85 1,815 2,385
15 Montgomery 105,195 76,640 6,085 1,105 8,810 3,105 7,615 80 1,755 35,725 50,710
16 Prince George's 84,190 53,900 2,770 1,025 6,370 5,815 11,420 75 2,815 24,310 32,780
17 Queen Anne's 7,050 5,030 310 50 545 225 695 15 180 2,395 2,825
18 St. Mary's 11,220 7,195 570 95 1,135 520 1,380 10 315 3,540 4,380
19 Somerset 4,625 3,055 155 55 385 180 665 10 120 1,365 1,830
20 Talbot 9,260 6,910 485 70 780 170 695 5 145 3,255 4,105
21 Washington 25,385 16,440 1,245 225 2,500 900 3,290 65 720 7,585 10,595
22 Wicomico 16,040 10,700 490 140 1,300 690 2,205 35 480 4,680 6,480
23 Worcester 13,365 10,235 440 70 965 275 1,130 20 230 4,605 5,765
So, I have these data given below, and my goal is to aggregate column v3 in terms of columns v1 and v2 and add the v3 values for each bin of v1 and v2. For example, the first line correspond to interval v1=21, v2=16, so the value of v3 will be aggregated over its (v1,v2) interval. And repeat this for the rest of rows. I want to use the mean as the aggregation function!
> df
v1 v2 v3
1 21.359 16.234 24.283
2 47.340 9.184 21.328
3 35.363 -13.258 14.556
4 -29.888 14.154 17.718
5 -10.109 -16.994 20.200
6 -32.387 1.722 15.735
7 49.240 -5.266 17.601
8 -38.933 2.558 16.377
9 41.213 5.937 21.654
10 -33.287 -4.028 19.525
11 -10.223 11.961 16.756
12 -48.652 16.558 20.800
13 44.778 27.741 17.793
14 -38.546 29.708 13.948
15 -45.622 4.729 17.793
16 -36.290 12.383 18.014
17 -19.626 19.767 18.182
18 -32.248 29.480 15.108
19 -41.859 35.502 8.490
20 -36.058 21.191 16.714
21 -23.588 0.524 21.471
22 -24.423 39.963 18.257
23 -0.042 -45.899 17.654
24 -35.479 32.049 9.294
25 -24.632 20.603 17.757
26 -26.591 25.882 18.968
27 -34.364 43.959 13.905
28 -19.334 29.728 20.102
29 12.304 -39.997 17.002
30 0.958 37.162 20.779
31 -35.475 -40.611 14.719
32 -39.268 44.382 11.247
33 -10.154 39.053 19.458
34 -12.612 32.056 17.759
35 2.730 -1.473 20.228
36 -45.326 -52.299 9.305
37 -1.996 -15.551 13.295
38 -26.655 -37.319 19.148
39 -18.509 -30.047 18.889
40 -22.705 -25.577 19.007
41 -15.705 -15.397 19.112
42 -2.637 9.790 10.548
43 -14.107 -3.145 19.654
44 -29.272 -19.906 18.503
45 -9.569 -4.632 11.334
46 2.114 18.048 14.744
47 -4.241 16.073 15.420
48 31.869 -3.394 21.559
49 20.425 35.205 22.250
50 -18.605 -8.866 20.082
51 -26.677 -7.690 21.850
52 -5.240 4.805 11.399
53 -6.766 2.538 6.292
54 4.567 22.554 19.682
55 -20.701 6.430 20.996
56 -23.972 16.141 17.976
57 -6.651 24.048 18.082
58 -32.243 -6.100 19.517
59 2.236 29.736 19.667
60 18.830 15.586 15.969
61 -9.598 28.414 17.806
62 -30.825 12.194 22.346
63 -17.415 15.795 18.135
64 -14.823 5.931 17.915
65 -14.234 12.882 13.001
66 9.937 18.368 20.421
67 -38.766 9.590 21.648
68 -30.896 27.047 16.453
69 -4.432 -10.562 10.061
70 -4.290 33.170 22.942
71 7.285 41.416 23.906
72 24.411 40.531 23.584
73 45.409 -32.420 20.831
74 49.341 -34.047 15.269
75 -7.730 -47.724 21.692
76 -10.563 -29.082 17.984
77 4.412 -41.182 16.845
78 31.822 -37.297 19.665
79 -43.355 31.093 17.688
80 -44.353 -44.723 13.832
81 -16.961 38.438 20.715
82 -21.225 -39.244 18.156
83 -42.022 -8.686 20.362
84 -42.904 -25.498 18.394
85 43.822 -25.990 21.287
86 43.013 -9.071 19.285
87 -36.901 -24.185 21.938
88 -28.251 -36.583 19.330
89 -19.830 -22.412 21.677
90 -3.789 -15.663 17.439
91 40.453 -21.796 17.432
92 -40.778 -31.188 18.762
93 -27.072 -48.609 18.913
94 -18.035 -1.791 19.909
95 -20.781 -7.912 22.563
96 47.307 -15.432 19.101
97 30.700 5.097 22.801
98 46.453 0.171 17.810
99 -27.439 -5.860 22.626
100 -30.526 -18.007 23.219
101 -18.280 -15.187 25.302
102 -18.367 6.044 18.864
103 41.265 -1.686 22.743
104 29.227 -14.814 19.196
105 -36.080 -32.715 18.930
106 7.475 7.061 25.002
107 -18.586 -45.207 21.864
108 35.227 11.148 21.388
109 -7.581 38.773 22.048
110 -43.685 14.083 22.037
111 -29.533 39.735 17.613
112 8.760 -39.400 22.421
113 -14.962 24.624 12.030
114 18.627 -32.888 23.036
115 -31.300 33.612 15.608
116 -38.024 45.839 16.567
117 -15.104 36.893 18.162
118 -12.809 -23.029 21.589
119 -21.614 36.264 16.680
120 42.917 -36.838 18.738
121 6.104 -14.961 14.468
122 44.032 -41.556 17.618
123 -24.493 21.886 17.366
124 -24.361 29.941 14.374
125 -25.060 43.383 16.437
126 -6.017 -24.640 19.207
127 -32.617 -40.549 18.059
128 -43.285 -43.364 18.827
129 -29.856 -46.089 16.881
130 -16.547 -43.619 22.547
131 -16.257 42.814 18.932
132 -9.236 -11.694 14.455
133 13.488 -35.422 24.436
134 -47.456 -32.714 18.123
135 39.476 -28.008 16.087
136 -21.933 -43.522 15.390
137 -17.347 -38.250 16.738
138 -4.948 -39.747 21.598
139 -31.018 -28.912 21.332
140 -36.364 30.461 17.542
141 -39.639 18.272 23.663
142 -24.162 -13.582 19.136
143 -8.935 -32.699 22.108
144 0.001 -19.219 17.888
145 -6.912 -24.885 20.683
146 7.785 -31.229 15.972
147 22.176 -7.478 21.335
148 8.755 -13.323 20.831
149 44.081 41.160 11.938
150 -8.451 -37.721 17.465
151 18.671 -2.776 23.374
152 12.668 -26.749 18.071
153 1.582 -21.252 20.750
154 20.832 -27.718 16.190
155 44.220 -45.690 12.598
156 -0.226 -37.737 17.634
157 -25.130 -19.197 23.170
158 2.086 -31.271 18.180
159 -20.445 -33.083 19.984
160 23.801 1.116 24.230
161 18.283 -17.922 20.256
162 -38.985 -13.770 20.702
163 -26.264 -27.413 20.276
164 10.396 -19.375 20.415
165 -16.343 -22.847 16.516
166 29.992 -8.215 21.661
167 35.052 -19.475 16.953
168 3.052 -6.800 22.509
169 -10.350 -5.413 19.222
170 14.371 -10.383 23.471
171 11.896 -4.191 21.773
172 18.152 8.741 23.669
173 25.748 -47.786 18.578
174 31.613 -0.735 23.898
175 12.660 25.645 23.549
176 2.933 29.345 25.170
177 9.369 18.791 26.817
178 15.805 4.798 27.866
179 27.556 -25.571 14.796
180 -5.112 -7.835 21.201
181 -30.571 3.471 20.496
182 19.816 -22.114 21.210
183 2.826 47.437 22.911
184 25.488 -33.064 21.442
185 44.826 42.162 22.994
186 25.208 -48.487 25.325
187 14.635 -17.430 17.083
188 -1.901 -33.370 22.163
189 12.306 -47.265 20.052
190 42.552 35.750 23.213
191 37.318 -46.069 22.599
192 4.725 -22.289 21.600
193 -40.815 -37.793 17.371
194 11.890 -12.862 14.286
195 35.251 -31.746 17.816
196 27.121 -27.638 19.677
197 36.024 -39.105 20.202
198 -47.119 41.940 17.526
199 0.837 -40.694 23.063
200 23.797 -39.795 20.198
201 -42.859 -21.372 23.554
202 39.407 -20.211 21.246
203 25.782 -18.892 20.423
204 34.529 -9.576 20.411
205 44.397 -13.247 23.180
206 5.534 6.856 14.248
207 31.598 -18.085 22.350
208 7.250 -0.481 15.453
209 -43.458 -15.204 23.193
210 -38.296 -31.524 21.776
211 4.276 -3.483 12.145
212 25.757 -11.708 22.360
213 15.634 37.478 24.624
214 -43.669 -3.197 20.742
215 45.381 6.365 21.351
216 -38.755 -6.877 20.879
217 -6.925 3.994 21.120
218 8.059 12.831 26.032
219 3.572 22.105 26.920
220 16.042 30.267 21.039
221 26.629 13.042 23.633
222 -12.126 -0.151 21.261
223 -11.981 24.600 19.236
224 29.480 28.362 21.838
225 -2.500 22.858 23.177
226 -41.163 19.863 20.059
227 35.953 27.401 19.101
228 -16.641 13.248 17.984
229 -3.778 14.090 18.943
230 11.643 34.817 21.621
231 34.921 38.666 17.359
232 25.621 22.451 22.866
233 34.936 17.384 19.836
234 40.017 37.599 13.987
235 19.547 33.838 22.575
236 11.197 39.977 19.347
237 16.972 -33.927 14.205
238 22.938 38.064 20.351
239 40.234 18.672 23.030
240 -0.846 42.320 18.383
241 -11.437 18.284 16.502
242 19.552 43.222 21.370
243 13.925 -46.486 18.917
244 41.709 -39.559 16.143
245 19.014 -44.563 17.796
246 32.260 33.114 18.402
247 -4.693 29.228 18.622
248 21.765 -38.452 15.147
249 39.157 -31.135 19.800
250 32.638 46.241 18.943
251 2.797 10.089 21.330
252 8.256 46.910 18.834
253 38.634 -2.429 20.413
254 28.642 2.763 19.580
255 0.456 1.422 7.452
256 3.050 11.792 14.196
257 24.736 14.532 17.886
258 16.787 -10.155 18.607
259 12.676 11.651 18.656
260 13.184 1.081 15.385
261 27.365 26.576 25.486
262 -7.878 -18.191 14.547
263 -42.112 32.576 20.865
264 15.069 21.684 17.986
265 33.045 27.166 25.252
266 21.810 -0.186 19.477
267 18.227 26.690 20.415
268 33.759 18.366 21.255
269 39.491 13.272 23.036
270 30.662 9.368 20.192
271 5.470 35.303 22.685
272 21.663 -44.343 20.999
273 31.261 33.178 24.335
274 21.854 22.665 20.876
275 21.853 7.932 18.588
276 -40.168 3.682 19.642
277 -42.292 23.997 22.199
278 10.233 28.731 21.263
279 17.745 41.831 19.536
280 38.406 25.165 26.534
281 -49.329 -0.465 20.887
282 40.398 -8.120 21.362
283 -2.531 46.118 22.933
284 7.959 -30.856 20.497
285 -34.467 -23.724 22.206
286 30.541 44.284 25.878
287 45.682 29.897 21.964
288 -22.251 -0.089 20.756
289 21.484 16.532 23.513
290 46.912 10.195 21.908
291 35.320 -13.352 16.102
292 -30.431 14.048 17.362
293 -8.976 -17.325 21.645
294 -32.661 2.301 16.805
295 49.317 -5.509 17.711
296 -37.756 4.459 16.054
297 41.445 6.158 21.442
298 -33.148 -3.499 19.543
299 -10.065 12.238 16.649
300 -48.323 17.153 20.974
301 45.010 28.147 17.838
302 -39.630 29.183 13.254
303 -45.191 5.065 18.214
304 -35.936 11.953 16.540
305 -19.816 19.624 18.279
306 -32.055 29.757 15.358
307 -41.533 36.169 10.005
308 -35.448 20.960 16.720
309 -23.384 0.511 20.005
310 -25.101 40.569 18.180
311 -0.547 -45.779 17.603
312 -35.291 32.643 9.548
313 -25.109 20.826 17.494
314 -26.202 27.012 18.678
315 -34.805 43.850 14.006
316 -18.819 30.611 20.309
317 13.019 -40.248 16.874
318 -0.655 37.112 20.924
319 -34.142 -41.553 15.237
320 -39.509 43.886 12.464
321 -9.491 38.639 18.839
322 -12.164 31.977 17.598
323 3.437 -1.596 20.318
324 -45.713 -52.599 9.918
325 -2.062 -15.946 12.847
326 -27.435 -37.600 18.257
327 -18.094 -29.624 18.791
328 -22.647 -26.123 18.746
329 -16.775 -15.505 19.204
330 -2.628 9.599 11.219
331 -15.718 -1.797 19.491
332 -29.476 -20.107 17.485
333 -10.618 -4.938 12.227
334 1.423 17.458 14.706
335 -4.503 16.630 14.718
336 32.450 -2.029 21.591
337 20.529 35.464 21.630
338 -19.348 -7.844 19.464
339 -26.760 -6.856 21.422
340 -4.539 4.393 11.819
341 -5.741 1.934 7.121
342 4.781 21.919 18.908
343 -19.797 6.928 20.928
344 -24.555 16.834 19.796
345 -5.664 24.465 18.432
346 -32.891 -6.571 18.691
347 2.354 28.462 19.825
348 18.058 16.251 16.335
349 -9.603 28.582 17.743
350 -31.282 11.454 22.342
351 -17.580 16.428 18.401
352 -13.884 6.206 17.270
353 -13.631 13.767 11.761
354 9.712 18.008 18.896
355 -37.987 9.024 21.309
356 -29.969 27.506 16.964
357 -4.248 -10.813 9.284
358 -5.755 32.673 22.541
359 6.675 41.952 24.227
360 24.564 41.173 23.241
361 45.314 -32.299 20.778
362 -45.890 -33.510 16.314
363 -8.277 -47.943 21.573
364 -11.044 -29.464 17.708
365 3.972 -41.396 17.411
366 31.776 -36.643 19.998
367 -43.072 31.311 17.828
368 -45.805 -43.071 14.477
369 -15.628 39.837 19.709
370 -21.129 -39.101 18.814
371 -41.628 -8.980 19.850
372 -42.244 -23.659 18.856
373 44.149 -25.710 21.099
374 42.623 -9.185 20.147
375 -35.949 -23.979 22.255
376 -28.512 -36.367 19.378
377 -19.827 -21.781 21.621
378 -3.429 -15.706 18.677
379 39.741 -20.721 18.670
380 -41.663 -29.499 19.260
381 -26.931 -48.467 18.185
382 -17.571 -1.467 19.770
383 -20.039 -7.591 22.737
384 46.370 -14.790 19.922
385 30.710 4.167 22.987
386 46.755 0.417 18.088
387 -27.293 -4.398 22.168
388 -30.364 -17.573 23.869
389 -16.870 -14.893 25.817
390 -18.152 6.546 18.392
391 40.134 0.160 23.661
392 28.179 -14.323 19.301
393 -35.907 -32.647 19.306
394 8.486 7.101 24.551
395 -17.155 -45.435 22.745
396 34.226 10.748 19.773
397 -7.760 38.754 22.211
398 -42.899 13.804 22.628
399 -29.972 40.435 17.784
400 8.764 -39.195 22.070
401 -15.624 25.585 12.291
402 18.620 -33.314 23.282
403 -30.436 34.219 15.102
404 -37.665 44.955 15.257
405 -15.861 37.488 18.956
406 -13.375 -22.408 20.312
407 -20.972 36.906 17.387
408 43.162 -35.948 19.695
409 6.639 -15.783 14.608
410 44.186 -41.037 17.398
411 -23.917 22.236 18.702
412 -23.957 30.033 14.725
413 -25.056 43.824 15.489
414 -6.795 -24.375 18.537
415 -33.485 -40.651 17.538
416 -43.186 -43.071 17.481
417 -30.325 -46.122 16.440
418 -17.489 -43.551 22.006
419 -16.376 43.928 18.992
420 -9.076 -10.921 14.131
421 13.704 -36.352 23.812
422 -47.302 -31.918 18.719
423 39.459 -27.814 15.558
424 -22.509 -42.660 14.366
425 -17.920 -37.614 16.572
426 -5.780 -39.212 21.667
427 -30.519 -28.942 21.931
428 -35.937 31.435 17.106
429 -38.680 18.435 23.342
430 -24.796 -13.279 18.543
431 -9.283 -32.388 21.895
432 0.493 -19.505 17.276
433 -7.046 -25.243 20.741
434 7.884 -32.006 16.727
435 22.451 -7.834 21.082
436 8.379 -13.690 22.002
437 43.730 41.697 11.894
438 -9.040 -38.086 17.500
439 18.831 -2.759 23.252
440 12.732 -27.410 18.948
441 0.739 -21.091 21.354
442 20.339 -27.959 16.514
443 44.688 -46.449 12.356
444 -0.402 -36.951 17.891
445 -24.790 -18.139 23.337
446 2.173 -30.577 18.023
447 -18.995 -33.799 20.730
448 23.372 0.223 24.855
449 17.835 -17.372 19.878
450 -38.915 -13.815 20.923
451 -26.241 -27.800 19.877
452 11.074 -18.156 19.249
453 -16.478 -22.928 16.386
454 29.646 -8.349 21.115
455 33.910 -20.809 16.629
456 3.306 -6.830 22.059
457 -10.512 -5.322 19.876
458 14.024 -10.406 23.456
459 12.365 -3.699 21.818
460 18.186 8.532 23.951
461 25.140 -47.653 18.592
462 32.288 -2.117 23.423
463 10.836 24.937 23.310
464 4.531 28.913 25.238
465 9.944 18.397 26.661
466 16.274 4.852 27.837
467 27.316 -26.007 15.934
468 -4.508 -8.010 20.906
469 -29.858 2.412 19.958
470 20.376 -21.957 21.306
471 2.077 47.431 23.248
472 25.777 -33.367 21.695
473 44.854 42.801 22.904
474 25.356 -48.833 25.402
475 15.322 -16.926 17.318
476 -2.656 -33.400 20.365
477 11.950 -47.390 20.328
478 42.961 36.955 22.919
479 35.726 -45.402 24.272
480 4.675 -21.758 21.780
481 -40.568 -36.931 16.934
482 11.758 -12.859 14.206
483 35.483 -31.760 16.975
484 27.336 -27.577 19.429
485 36.689 -39.218 19.668
486 -46.357 41.618 17.456
487 0.002 -40.589 22.558
488 23.525 -39.918 21.247
489 -43.269 -21.304 22.699
490 40.191 -20.594 21.145
491 25.728 -18.024 20.298
492 34.964 -10.441 20.189
493 43.627 -13.279 23.038
494 5.766 6.876 14.077
495 32.432 -18.172 21.848
496 7.087 -1.122 15.098
497 -44.110 -14.034 23.080
498 -39.474 -31.289 22.312
499 4.118 -4.077 11.067
500 26.597 -11.667 22.641
so, using these commands I can find the intervals, as below
x.bin <- seq(floor(min(d[,1])), ceiling(max(df[,1])), by=2)
y.bin <- seq(floor(min(d[,2])), ceiling(max(df[,2])), by=2)
> x.bin
[1] -50 -48 -46 -44 -42 -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14
[20] -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24
[39] 26 28 30 32 34 36 38 40 42 44 46 48 50
> y.bin
[1] -53 -51 -49 -47 -45 -43 -41 -39 -37 -35 -33 -31 -29 -27 -25 -23 -21 -19 -17
[20] -15 -13 -11 -9 -7 -5 -3 -1 1 3 5 7 9 11 13 15 17 19 21
[39] 23 25 27 29 31 33 35 37 39 41 43 45 47
But, then I don't know how to assign each row of the raw data (df) to each x.bin and y.bin and calculate the aggregate (sum) of each bin.
library(plyr)
#I am using cut function with 50 breaks for both v1 and v2 and ddply from plyr package for computing the mean
newdata<-ddply(df,.(cut(v1,50),cut(v2,50)),summarise,mean.v3=mean(v3))
> head(newdata)
cut(v1, 50) cut(v2, 50) mean.v3
1 (-49.4,-47.5] (-34.7,-32.7] 18.123
2 (-49.4,-47.5] (-0.576,1.43] 20.887
3 (-49.4,-47.5] (15.5,17.5] 20.887
4 (-47.5,-45.5] (-52.7,-50.7] 9.918
5 (-47.5,-45.5] (-44.7,-42.7] 14.477
6 (-47.5,-45.5] (-34.7,-32.7] 16.314
Updated as per the comments: If you want the lower, middle and mid-points, you can use the following function or use with details as follow(you need to use the sub function to deal with ( and ]):
df$newv1<-with(df,cut(v1,50))
df$newv2<-with(df,cut(v2,50))
df$lowerv1<-with(df,as.numeric( sub("\\((.+),.*", "\\1", newv1))) #lower value
df$upperv1<-with(df,as.numeric( sub("[^,]*,([^]]*)\\]", "\\1", newv1))) # upper value
df$midv1<-with(df,(lowerv1+upperv1)/2) #mid value
df$lowerv2<-with(df,as.numeric( sub("\\((.+),.*", "\\1",newv2))) #lower value
df$upperv2<-with(df,as.numeric( sub("[^,]*,([^]]*)\\]", "\\1", newv2))) # upper value
df$midv2<-with(df,(lowerv2+upperv2)/2)#mid value
newdata<-ddply(df,.(newv1,newv2),transform,mean.v3=mean(v3))
> head(newdata)
v1 v2 v3 newv1 newv2 lowerv1 upperv1 midv1 lowerv2 upperv2 midv2 mean.v3
1 -47.456 -32.714 18.123 (-49.4,-47.5] (-34.7,-32.7] -49.4 -47.5 -48.45 -34.700 -32.70 -33.700 18.123
2 -49.329 -0.465 20.887 (-49.4,-47.5] (-0.576,1.43] -49.4 -47.5 -48.45 -0.576 1.43 0.427 20.887
3 -48.652 16.558 20.800 (-49.4,-47.5] (15.5,17.5] -49.4 -47.5 -48.45 15.500 17.50 16.500 20.887
4 -48.323 17.153 20.974 (-49.4,-47.5] (15.5,17.5] -49.4 -47.5 -48.45 15.500 17.50 16.500 20.887
5 -45.713 -52.599 9.918 (-47.5,-45.5] (-52.7,-50.7] -47.5 -45.5 -46.50 -52.700 -50.70 -51.700 9.918
6 -45.805 -43.071 14.477 (-47.5,-45.5] (-44.7,-42.7] -47.5 -45.5 -46.50 -44.700 -42.70 -43.700 14.477