{"action":"opened","issue":{"url":"https://api.github.com/repos/chingpo/chingpo.github.com/issues/1","repository_url":"https://api.github.com/repos/chingpo/chingpo.github.com","labels_url":"https://api.github.com/repos/chingpo/chingpo.github.com/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/chingpo/chingpo.github.com/issues/1/comments","events_url":"https://api.github.com/repos/chingpo/chingpo.github.com/issues/1/events","html_url":"https://github.com/chingpo/chingpo.github.com/issues/1","id":167219017,"number":1,"title":"人口数据的部分可视化","user":{"login":"chingpo","id":14759945,"avatar_url":"https://avatars.githubusercontent.com/u/14759945?v=3","gravatar_id":"","url":"https://api.github.com/users/chingpo","html_url":"https://github.com/chingpo","followers_url":"https://api.github.com/users/chingpo/followers","following_url":"https://api.github.com/users/chingpo/following{/other_user}","gists_url":"https://api.github.com/users/chingpo/gists{/gist_id}","starred_url":"https://api.github.com/users/chingpo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chingpo/subscriptions","organizations_url":"https://api.github.com/users/chingpo/orgs","repos_url":"https://api.github.com/users/chingpo/repos","events_url":"https://api.github.com/users/chingpo/events{/privacy}","received_events_url":"https://api.github.com/users/chingpo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-24T05:54:55Z","updated_at":"2016-07-24T05:54:55Z","closed_at":null,"body":"---\r\ntitle:\"data visualization\"\r\nauthor:\"Yan Jingbo\"\r\ndate:\"2016/4/4\"\r\n\r\n---\r\n\r\n\r\n```{r setup, include=FALSE}\r\nknitr::opts_chunk$set(echo = TRUE)\r\n```\r\n\r\n\r\n\r\n# week-4\r\n##1. rechart\r\n This tool originates from a top-tier d3-js visualization project of China: Baidu Echarts(Github Repo). Yang Zhou and Taiyun Wei developed an experimental R package recharts based on it, which then evoluted into yihui/recharts by Yihui Xie to pass js parameters through htmlwidgets. The package is sill uder development. I developed a function echartR based on this package to make basic Echarts interation charts. This function requires R>=3.2.0.\r\nThe basic examples of echart is as follows, which does not provide parameters entries other than dataset itself.\r\n [download rechart from here]<https://github.com/taiyun/recharts>.\r\n\r\n```{r iris, echo=TRUE, message=FALSE, warning=FALSE, warnings=FALSE}\r\nsource(\"F:/Rworkspace/echartR.R\")\r\nechartR(data = iris, x = ~Sepal.Width, y = ~Petal.Width, \r\n        type = 'scatter', palette='solarized_magenta',\r\n        title = 'Scatter - Sepal Width vs Petal Width', \r\n        subtitle = \"(source: iris)\", xlab = 'Sepal Width', ylab = 'Petal Width',\r\n        markLine=t(c(1,'Mean',\"average\",F)))\r\n```\r\n\r\n##2. data\r\n\r\n###2.1make data look like this:\r\n\r\n```{r pressure, echo=FALSE, message=FALSE, warning=FALSE}\r\nload(\"F:/Rworkspace/iall06h.Rdata\")\r\ndata<-iall06h\r\ndata[1,]\r\n```\r\n\r\n###2.2 bar\r\n```{r, echo=FALSE}\r\ndata[,13]<-data[,2]+data[,3]+data[,4]+data[,5]+data[,6]+data[,7]+data[,8]+data[,9]+data[,10]+data[,11]+data[,12]\r\nnames(data)[13]<-\"total\"\r\nj<-1;k<-1;l<-1;m<-1;z<-1;o<-1;p<-1;q<-1;r<-1;\r\nt21<-data[1,];t23<-data[1,];t32<-data[1,];t37<-data[1,];t41<-data[1,];t42<-data[1,];t43<-data[1,];t45<-data[1,];t52<-data[1,];\r\nfor(n in 1:nrow(data)){\r\n    if(substring(data[n,1],1,2)==\"21\"){t21[j,]<-data[n,];j<-j+1;}\r\n    else if(substring(data[n,1],1,2)==\"23\"){t23[k,]<-data[n,];k<-k+1;}\r\n    else if(substring(data[n,1],1,2)==\"32\"){t32[l,]<-data[n,];l<-l+1;}\r\n    else if(substring(data[n,1],1,2)==\"37\"){t37[m,]<-data[n,];m<-m+1;}\r\n    else if(substring(data[n,1],1,2)==\"41\"){t41[z,]<-data[n,];z<-z+1;}\r\n    else if(substring(data[n,1],1,2)==\"42\"){t42[o,]<-data[n,];o<-o+1;}\r\n    else if(substring(data[n,1],1,2)==\"43\"){t43[p,]<-data[n,];p<-p+1;}\r\n    else if(substring(data[n,1],1,2)==\"45\"){t45[q,]<-data[n,];q<-q+1;}\r\n    else if(substring(data[n,1],1,2)==\"52\"){t52[r,]<-data[n,];r<-r+1;}\r\n}\r\ns21<-colSums(t21);s23<-colSums(t23);s32<-colSums(t32);s37<-colSums(t37);\r\ns41<-colSums(t41);s42<-colSums(t42);s43<-colSums(t43);s45<-colSums(t45);s52<-colSums(t52)\r\nst21<-s21[13];st23<-s23[13];st32<-s32[13];st37<-s37[13];st41<-s41[13];st42<-s42[13];st43<-s43[13];st45<-s45[13];st52<-s52[13];\r\nsbar<-c(st21,st23,st32,st37,st41,st42,st43,st45,st52)\r\nsspecie<-c(\"t\",\"t\",\"t\",\"t\",\"t\",\"t\",\"t\",\"t\",\"t\")\r\nsname<-c(\"辽宁\",\"黑龙江\",\"江苏\",\"山东\",\"河南\",\"湖北\",\"湖南\",\"广西\",\"贵州\")\r\nsbart<-data.frame(sname,sbar,sspecie)\r\nspie<-data.frame(sname,sbar)\r\n\r\nnames(sbart)<-c(\"province\",\"income\",\"species\")\r\nnames(spie)<-c(\"province\",\"income\")\r\nspie\r\n```\r\n###3.3 pie\r\n```{r}\r\nsource(\"F:/Rworkspace/echartR.R\")\r\nechartR(data = sbart, x = ~province, y =~income,series = ~species,\r\n        type = 'bar', palette='solarized_magenta',\r\n        title = \"general income\", \r\n        subtitle = '(source:chns)', pos=list(legend=3),\r\n        xlab = 'province', ylab = 'income')\r\n\r\n```\r\n```{r}\r\nsource(\"F:/Rworkspace/echartR.R\")\r\nechartR(data = sbart, x = ~province, y =~income,series = ~income,\r\n        type = 'pie', palette='fivethirtyeight',\r\n        title = \"general income\", \r\n        subtitle = '(source:chns)', pos=list(legend=3))\r\n```\r\n\r\n"}}
{"actor":{"display_login":"chingpo"}}