Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramnathv/8fca6e067c08b4b1ee3c to your computer and use it in GitHub Desktop.
Save ramnathv/8fca6e067c08b4b1ee3c to your computer and use it in GitHub Desktop.
Higcharts Series Deselection
data(tips, package = 'reshape2')
a <- hPlot(tip ~ total_bill, group = 'day', data = tips, type = 'scatter')
visible = c("Fri", "Sat")
a$params$series = lapply(seq_along(a$params$series), function(i){
x = a$params$series[[i]]
x$visible = x$name %in% visible
return(x)
})
a
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='//code.jquery.com/jquery-1.9.1.min.js' type='text/javascript'></script>
<script src='//code.highcharts.com/highcharts.js' type='text/javascript'></script>
<script src='//code.highcharts.com/highcharts-more.js"' type='text/javascript'></script>
<script src='//code.highcharts.com/modules/exporting.js' type='text/javascript'></script>
<style>
.rChart {
display: block;
margin-left: auto;
margin-right: auto;
width: 600px;
height: 400px;
}
</style>
</head>
<body >
<div id = 'chartb6685a4e8f6c' class = 'rChart highcharts'></div>
<script type='text/javascript'>
(function($){
$(function () {
var chart = new Highcharts.Chart({
"dom": "chartb6685a4e8f6c",
"width": 600,
"height": 400,
"credits": {
"href": null,
"text": null
},
"exporting": {
"enabled": false
},
"title": {
"text": null
},
"yAxis": [
{
"title": {
"text": "tip"
}
}
],
"series": [
{
"data": [
[
5.75,
1
],
[
8.58,
1.92
],
[
10.09,
2
],
[
11.35,
2.5
],
[
12.03,
1.5
],
[
12.16,
2.2
],
[
12.46,
1.5
],
[
13.42,
1.58
],
[
13.42,
3.48
],
[
15.38,
3
],
[
15.98,
3
],
[
16.27,
2.5
],
[
16.32,
4.3
],
[
21.01,
3
],
[
22.49,
3.5
],
[
22.75,
3.25
],
[
27.28,
4
],
[
28.97,
3
],
[
40.17,
4.73
]
],
"name": "Fri",
"type": "scatter",
"marker": {
"radius": 3
},
"visible": true
},
{
"data": [
[
3.07,
1
],
[
7.25,
1
],
[
7.74,
1.44
],
[
9.55,
1.45
],
[
10.07,
1.25
],
[
10.51,
1.25
],
[
10.59,
1.61
],
[
10.63,
2
],
[
10.77,
1.47
],
[
11.02,
1.98
],
[
11.24,
1.76
],
[
11.59,
1.5
],
[
11.61,
3.39
],
[
12.02,
1.97
],
[
12.6,
1
],
[
12.69,
2
],
[
12.76,
2.23
],
[
12.9,
1.1
],
[
13.27,
2.5
],
[
13.28,
2.72
],
[
13.37,
2
],
[
13.81,
2
],
[
14,
3
],
[
14.31,
4
],
[
14.73,
2.2
],
[
15.01,
2.09
],
[
15.06,
3
],
[
15.36,
1.64
],
[
15.53,
3
],
[
15.69,
3
],
[
15.77,
2.23
],
[
15.81,
3.16
],
[
16.04,
2.24
],
[
16.31,
2
],
[
16.45,
2.47
],
[
16.93,
3.07
],
[
17.07,
3
],
[
17.59,
2.64
],
[
17.78,
3.27
],
[
17.81,
2.34
],
[
17.82,
1.75
],
[
17.92,
3.08
],
[
17.92,
4.08
],
[
18.24,
3.76
],
[
18.29,
3.76
],
[
18.35,
2.5
],
[
18.69,
2.31
],
[
19.65,
3
],
[
19.82,
3.18
],
[
20.08,
3.15
],
[
20.23,
2.01
],
[
20.29,
2.75
],
[
20.29,
3.21
],
[
20.45,
3
],
[
20.49,
4.06
],
[
20.65,
3.35
],
[
20.69,
2.45
],
[
20.92,
4.08
],
[
21.7,
4.3
],
[
22.12,
2.88
],
[
22.42,
3.48
],
[
22.67,
2
],
[
24.01,
2
],
[
24.06,
3.6
],
[
24.27,
2.03
],
[
25.21,
4.29
],
[
25.28,
5
],
[
25.89,
5.16
],
[
26.41,
1.5
],
[
26.59,
3.41
],
[
26.86,
3.14
],
[
27.18,
2
],
[
28.15,
3
],
[
28.17,
6.5
],
[
29.03,
5.92
],
[
30.06,
2
],
[
30.14,
3.09
],
[
31.27,
5
],
[
32.83,
1.17
],
[
35.83,
4.67
],
[
38.01,
3
],
[
38.73,
3
],
[
39.42,
7.58
],
[
44.3,
2.5
],
[
48.27,
6.73
],
[
48.33,
9
],
[
50.81,
10
]
],
"name": "Sat",
"type": "scatter",
"marker": {
"radius": 3
},
"visible": true
},
{
"data": [
[
7.25,
5.15
],
[
8.77,
2
],
[
9.6,
4
],
[
9.68,
1.32
],
[
9.94,
1.56
],
[
10.27,
1.71
],
[
10.29,
2.6
],
[
10.33,
1.67
],
[
10.34,
1.66
],
[
12.54,
2.5
],
[
12.66,
2.5
],
[
13.13,
2
],
[
13.39,
2.61
],
[
13.81,
2
],
[
13.94,
3.06
],
[
14.07,
2.5
],
[
14.48,
2
],
[
14.78,
3.23
],
[
14.83,
3.02
],
[
15.04,
1.96
],
[
15.42,
1.57
],
[
15.69,
1.5
],
[
16.21,
2
],
[
16.29,
3.71
],
[
16.49,
2
],
[
16.82,
4
],
[
16.97,
3.5
],
[
16.99,
1.01
],
[
17.26,
2.74
],
[
17.31,
3.5
],
[
17.46,
2.54
],
[
17.51,
3
],
[
17.89,
2
],
[
18.04,
3
],
[
18.15,
3.5
],
[
18.29,
3
],
[
18.43,
3
],
[
19.49,
3.51
],
[
19.77,
2
],
[
20.69,
5
],
[
20.76,
2.24
],
[
20.9,
3.5
],
[
21.01,
3.5
],
[
21.5,
3.5
],
[
21.58,
3.92
],
[
22.23,
5
],
[
23.1,
4
],
[
23.17,
6.5
],
[
23.33,
5.65
],
[
23.68,
3.31
],
[
23.95,
2.55
],
[
24.52,
3.48
],
[
24.55,
2
],
[
24.59,
3.61
],
[
25,
3.75
],
[
25.29,
4.71
],
[
25.56,
4.34
],
[
25.71,
4
],
[
26.88,
3.12
],
[
28.55,
2.05
],
[
29.85,
5.14
],
[
29.93,
5.07
],
[
30.4,
5.6
],
[
30.46,
2
],
[
31.71,
4.5
],
[
31.85,
3.18
],
[
32.4,
6
],
[
32.9,
3.11
],
[
34.63,
3.55
],
[
34.65,
3.68
],
[
34.81,
5.2
],
[
35.26,
5
],
[
38.07,
4
],
[
40.55,
3
],
[
45.35,
3.5
],
[
48.17,
5
]
],
"name": "Sun",
"type": "scatter",
"marker": {
"radius": 3
},
"visible": false
},
{
"data": [
[
7.51,
2
],
[
7.56,
1.44
],
[
8.35,
1.5
],
[
8.51,
1.25
],
[
8.52,
1.48
],
[
9.78,
1.73
],
[
10.07,
1.83
],
[
10.33,
2
],
[
10.34,
2
],
[
10.65,
1.5
],
[
11.17,
1.5
],
[
11.38,
2
],
[
11.69,
2.31
],
[
11.87,
1.63
],
[
12.26,
2
],
[
12.43,
1.8
],
[
12.48,
2.52
],
[
12.74,
2.01
],
[
13,
2
],
[
13,
2
],
[
13.03,
2
],
[
13.16,
2.75
],
[
13.42,
1.68
],
[
13.51,
2
],
[
14.15,
2
],
[
14.26,
2.5
],
[
14.52,
2
],
[
15.48,
2.02
],
[
15.95,
2
],
[
15.98,
2.03
],
[
16,
2
],
[
16.4,
2.5
],
[
16.43,
2.3
],
[
16.47,
3.23
],
[
16.58,
4
],
[
16.66,
3.4
],
[
17.29,
2.71
],
[
17.47,
3.5
],
[
18.26,
3.25
],
[
18.28,
4
],
[
18.64,
1.36
],
[
18.71,
4
],
[
18.78,
3
],
[
19.08,
1.5
],
[
19.44,
3
],
[
19.81,
4.19
],
[
20.27,
2.83
],
[
20.53,
4
],
[
21.16,
3
],
[
22.76,
3
],
[
22.82,
2.18
],
[
24.08,
2.92
],
[
24.71,
5.85
],
[
27.05,
5
],
[
27.2,
4
],
[
28.44,
2.56
],
[
29.8,
4.2
],
[
32.68,
5
],
[
34.3,
6.7
],
[
34.83,
5.17
],
[
41.19,
5
],
[
43.11,
5
]
],
"name": "Thur",
"type": "scatter",
"marker": {
"radius": 3
},
"visible": false
}
],
"xAxis": [
{
"title": {
"text": "total_bill"
}
}
],
"subtitle": {
"text": null
},
"id": "chartb6685a4e8f6c",
"chart": {
"renderTo": "chartb6685a4e8f6c"
}
});
});
})(jQuery);
</script>
<script></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment