Last active
August 29, 2015 14:09
-
-
Save saurfang/41265ce302193c23cd77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rCharts) | |
library(httr) | |
library(RJSONIO) | |
Sys.setlocale(locale = "Chinese") | |
paresed_data <- read.csv("D:/Downloads/gb2312.csv",header = TRUE,sep = ",",quote="\"", stringsAsFactors = FALSE) | |
# rawcsv <- tempfile() | |
# write.csv(paresed_data, rawcsv, row.names = FALSE, fileEncoding = "utf-8") | |
# paresed_data <- read.csv(rawcsv, fileEncoding = "utf-8", encoding = "UTF-8", stringsAsFactors = FALSE) | |
# unlink(rawcsv) | |
data <- subset(paresed_data,select = c(title,name,id)) | |
tmp_data <- data.frame(table(data$id),stringsAsFactors = FALSE) | |
descs <- data[!duplicated(data$id),] | |
descs <- subset(descs,select = c(title,name)) | |
msg_cnt <- tmp_data$Freq | |
id <- tmp_data$Var1 | |
df <- data.frame(id,msg_cnt,descs, stringsAsFactors = FALSE) | |
df <- head(x = df,n = 20) | |
# df$title <- iconv(df$title, "gb2312", "UTF-8") | |
# df$name <- iconv(df$name, "gb2312", "UTF-8") | |
colnames(df) <- c("id","msgCnt","title","name") | |
h2 <- hPlot( | |
x = "id", | |
y = "msgCnt", | |
data = df, | |
type = "scatter", | |
title = "top n speakers", | |
group ="title" | |
) | |
h2 | |
h2$save("test.html") | |
h2$publish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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: 800px; | |
height: 400px; | |
} | |
</style> | |
</head> | |
<body > | |
<div id = 'chart130c4bc7a81' class = 'rChart highcharts'></div> | |
<script type='text/javascript'> | |
(function($){ | |
$(function () { | |
var chart = new Highcharts.Chart({ | |
"dom": "chart130c4bc7a81", | |
"width": 800, | |
"height": 400, | |
"credits": { | |
"href": null, | |
"text": null | |
}, | |
"exporting": { | |
"enabled": false | |
}, | |
"title": { | |
"text": "top n speakers" | |
}, | |
"yAxis": [ | |
{ | |
"title": { | |
"text": "msgCnt" | |
} | |
} | |
], | |
"series": [ | |
{ | |
"data": [ | |
[ | |
"199324957", | |
2 | |
], | |
[ | |
"21248331", | |
25 | |
], | |
[ | |
"2317757855", | |
8 | |
], | |
[ | |
"2431337263", | |
10 | |
], | |
[ | |
"304825802", | |
64 | |
] | |
], | |
"name": " ", | |
"type": "scatter", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
"1534574360", | |
5 | |
] | |
], | |
"name": "传说", | |
"type": "scatter", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
"1060958091", | |
155 | |
], | |
[ | |
"11440033", | |
168 | |
], | |
[ | |
"1259603175", | |
1 | |
] | |
], | |
"name": "大神", | |
"type": "scatter", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
"107005566", | |
4 | |
], | |
[ | |
"1417936287", | |
2 | |
], | |
[ | |
"258252204", | |
6 | |
] | |
], | |
"name": "精英", | |
"type": "scatter", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
"247103527", | |
39 | |
] | |
], | |
"name": "小白", | |
"type": "scatter", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
"1000000", | |
1 | |
], | |
[ | |
"1827292713", | |
8 | |
], | |
[ | |
"2649447211", | |
72 | |
] | |
], | |
"name": "新人", | |
"type": "scatter", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
"10000", | |
3 | |
], | |
[ | |
"1126265790", | |
2 | |
], | |
[ | |
"1792721412", | |
1 | |
], | |
[ | |
"2478272344", | |
8 | |
] | |
], | |
"name": "元老", | |
"type": "scatter", | |
"marker": { | |
"radius": 3 | |
} | |
} | |
], | |
"xAxis": [ | |
{ | |
"title": { | |
"text": "id" | |
}, | |
"categories": [ "10000", "1000000", "1060958091", "107005566", "1126265790", "11440033", "1259603175", "1417936287", "1534574360", "1792721412", "1827292713", "199324957", "21248331", "2317757855", "2431337263", "247103527", "2478272344", "258252204", "2649447211", "304825802" ] | |
} | |
], | |
"subtitle": { | |
"text": null | |
}, | |
"id": "chart130c4bc7a81", | |
"chart": { | |
"renderTo": "chart130c4bc7a81" | |
} | |
}); | |
}); | |
})(jQuery); | |
</script> | |
<script></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment