{"id":16292,"date":"2014-12-08T16:52:25","date_gmt":"2014-12-08T11:22:25","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=16292"},"modified":"2016-12-19T15:04:57","modified_gmt":"2016-12-19T09:34:57","slug":"visualization-using-r-and-googlevis","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/visualization-using-r-and-googlevis\/","title":{"rendered":"Visualization using R and googleVis"},"content":{"rendered":"<p>We at <a href=\"http:\/\/www.tothenew.com\">IntelliGrape <\/a>divide Big Data into four major sectors &#8211; as we commonly refer as 4C&#8217;s \u00a0of Big Data.<\/p>\n<p>These 4C&#8217;s are:-<\/p>\n<ul>\n<li>Capture (Data Ingestion)<\/li>\n<li>Contain (Data Persistence (NoSQL)<\/li>\n<li>Compute (Data Processing)<\/li>\n<li>Comprehend (Data Analytics\u00a0and Visualization)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Within this blog,\u00a0I&#8217;ll be focusing on the last pointer i.e. Comprehend part of Big Data &#8211; precisely the Visualization.<\/p>\n<p>The below image showcases the 4Cs with the technology stack that we use\u00a0across the projects.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/12\/Annotate-Your-Screenshot-2014-12-08-16-40-021.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-16306\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/12\/Annotate-Your-Screenshot-2014-12-08-16-40-021.png\" alt=\"Annotate Your Screenshot 2014-12-08 16-40-02\" width=\"534\" height=\"234\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2014\/12\/Annotate-Your-Screenshot-2014-12-08-16-40-021.png 504w, \/blog\/wp-ttn-blog\/uploads\/2014\/12\/Annotate-Your-Screenshot-2014-12-08-16-40-021-300x131.png 300w\" sizes=\"(max-width: 534px) 100vw, 534px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Visualization can be considered as\u00a0the face to your\u00a0Big Data and no one can undermine \u00a0the importance of \u00a0the face value. More usable,\u00a0intuitive and customized \u00a0interface to your\u00a0<strong>numbers<\/strong>, more value it can potentially draw for\u00a0any kind of business use case, \u00a0irrespective of the nature of data.<\/p>\n<p>We have a\u00a0diverse exposure in Visualization with industry leading technologies like <strong>Tableau<\/strong>. But in this blog, I&#8217;ll be talking about an small\u00a0open source view APIs\u00a0that we came across recently while\u00a0working in a project.<\/p>\n<p>We were supposed to produce a view of a Time Series representational over multiple factors. The view was also supposed to dynamically support the axis represenation based on whatever data type you\u00a0operate. Apart from this, multiple\u00a0variants could be applied on the same view. \u00a0There are various tools that can achieve this but specifically here I would like to\u00a0\u00a0mention about <strong>gvis\u00a0<\/strong> &#8211; which is a great charting APIs\u00a0when you want to show something varying overtime in a form of animated view.\u00a0\u00a0Though, animations are generally not supposed to be a good choice for data representation &#8211; but that&#8217;s a subjective discussion.<\/p>\n<p><strong>Scenario<\/strong>: We had to talk to HDFS through R-HDFS connector, displaying time series data based on extreme dynamism. So, this problem will tackled using <strong>gvisMotionChart<\/strong>\u00a0API, which I&#8217;ll be explaining below.<\/p>\n<p>We wanted\u00a0to draw motion graph on web-interface using R with the help of shiny, so here I have used\u00a0<strong>gvisMotionChart<\/strong> for drawing the motion graph in R.<\/p>\n<p><strong>gvisMotionChart<\/strong> provides the different types of parameters like changing the axis dynamically, provides the different type of filters, changes the graph from motion to line.<\/p>\n<p>Graph output:<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/12\/Google-Motion-Graph-2014-12-08-14-59-44.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-16296 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/12\/Google-Motion-Graph-2014-12-08-14-59-44-1024x509.png\" alt=\"Google Motion Graph 2014-12-08 14-59-44\" width=\"640\" height=\"318\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2014\/12\/Google-Motion-Graph-2014-12-08-14-59-44-1024x509.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2014\/12\/Google-Motion-Graph-2014-12-08-14-59-44-300x149.png 300w, \/blog\/wp-ttn-blog\/uploads\/2014\/12\/Google-Motion-Graph-2014-12-08-14-59-44.png 1610w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Here is datasets of the sale <a title=\"SalesData\" href=\"https:\/\/github.com\/IntelliGrape\/bigdata-poc\/blob\/master\/googleMotionChart\/data\/state.csv\">SalesData<\/a>.<\/p>\n<p>Our datasets contains sales, state, profit, quantity, time. As per the use case, we wanted to show a visualization using all these parameters dynamically, overtime and \u00a0also represent the output view in\u00a0different variants of graph with in same component.<\/p>\n<p><strong>Technologies Used:<\/strong><\/p>\n<ul>\n<li>R: Statistical Analysis Tool<\/li>\n<li>Shiny: Used as a web interface for R<\/li>\n<li>R-HDFS: Connector for R to HDFS<\/li>\n<li>HDFS: Where our datasets resides<\/li>\n<li>gvisMotionChart: Plugin to R<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Here is the step-by-step method for creating a chart using gvisMotionChart API.<\/p>\n<p>So in our use case, we need to push the csv file in HDFS,<\/p>\n<p>Here location is \/user\/data\/state_aggregated_data\/state.csv.<br \/>\nFor gvisMotionChart, we are using following sniplets in R to show the motion graph.<\/p>\n<p>[java]<br \/>\n    hdfs.init();<br \/>\n    brandGeoTrancs = hdfs.file(&quot;\/user\/data\/state_aggregated_data\/state.csv&quot;,&quot;r&quot;,buffersize=104857600);<br \/>\n    brandGeoRead = hdfs.read(brandGeoTrancs);<br \/>\n    brandGeoChar = rawToChar(brandGeoRead);<br \/>\n    stateAggregatedData = read.table(textConnection(brandGeoChar), sep = &quot;\\t&quot;);<br \/>\n    stateAggregatedData$Id&lt;-stateAggregatedData$State<br \/>\n    stateAggregatedData$Profit &lt;- as.numeric(stateAggregatedData$Profit)<br \/>\n    stateAggregatedData$Sale &lt;- as.numeric(stateAggregatedData$Sale)<br \/>\n    stateAggregatedData$Year &lt;- as.integer(stateAggregatedData$Year)<br \/>\n    stateAggregatedData$OrderQuantity &lt;- as.numeric(stateAggregatedData$OrderQuantity)<br \/>\n    gvisMotionChart(stateAggregatedData,idvar=&quot;Id&quot;,timevar=&quot;Year&quot;,yvar=&quot;OrderQuantity&quot;,xvar=&quot;Sale&quot;,options=list(height=750, width=1500))<br \/>\n[\/java]<\/p>\n<p>In above mentioned code, we are making the connection with HDFS, pulling data from it, converting numbers into numeric and showing the motion graph.<\/p>\n<p>[java]gvisMotionChart(stateAggregatedData,idvar=&quot;Id&quot;,timevar=&quot;Year&quot;,yvar=&quot;OrderQuantity&quot;,xvar=&quot;Sale&quot;,options=list(height=750, width=1500))<br \/>\n[\/java]<\/p>\n<p>This is the main method for showing the <strong>gvisMotionChart<\/strong>.<br \/>\nHere <strong>idVar<\/strong> and <strong>timeVar<\/strong> both combination should be unique for the datasets.<br \/>\n<strong>timeVar\u00a0<\/strong>&#8211; shows the year in slider<\/p>\n<p>For whole source code: <a href=\"https:\/\/github.com\/IntelliGrape\/bigdata-poc\/tree\/master\/googleMotionChart\">GitHub Location<\/a><\/p>\n<p>Hope this blog helps you !!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We at IntelliGrape divide Big Data into four major sectors &#8211; as we commonly refer as 4C&#8217;s \u00a0of Big Data. These 4C&#8217;s are:- Capture (Data Ingestion) Contain (Data Persistence (NoSQL) Compute (Data Processing) Comprehend (Data Analytics\u00a0and Visualization) &nbsp; Within this blog,\u00a0I&#8217;ll be focusing on the last pointer i.e. Comprehend part of Big Data &#8211; precisely [&hellip;]<\/p>\n","protected":false},"author":47,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[1395],"tags":[1396,1568,1567,1398,1516,1565,1566],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/16292"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=16292"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/16292\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=16292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=16292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=16292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}