<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/department-of-consumer-affairs-charges/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nycdatascience.com/blog/student-works/r-visualization/department-of-consumer-affairs-charges/"> R – NYC Data Science Academy Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img sizes="(max-width: 1024px) 100vw, 1024px" src="https://i2.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/02/dcaimage-1024x410.jpg?w=450&ssl=1" alt="" class="wp-post-image" data-recalc-dims="1"></p>
<h3>The Charges Data Set</h3>
<p>The NYC Open Data project provides the <a rel="nofollow" href="https://data.cityofnewyork.us/Business/Charges/5fn4-dr26" target="_blank">Department of Consumer Affairs data from 2016-2017</a>.  The Department of Consumer Affairs was started in 1969 with the goal to “ensure compliance with local consumer protection and licensing laws, and State and federal regulations.”  They oversee almost <a rel="nofollow" href="http://www1.nyc.gov/site/dca/about/consumer-protection-and-licensing-laws.page" target="_blank">every industry</a> in NYC.  This data set describes the charges brought against NYC businesses and through analysis, can reflect how the enforcement plays out in practical terms.</p>
<p>It contains 50, 000 rows, which includes location data, some categorical information such as borough and business category, but not too much numerical information.  This project had to rely heavily upon <em>count</em> of charges for the visualizations.  A lot of time was spent on parsing through the Charge descriptions which were challenging to categorize.</p>
<p>Here’s a sample of what the Charge descriptions looked like:</p>
<p><span>“NYC Admin Code § 20-822(a) – SALE OF EXPIRED MEDS:  BUSINESS OFFERED FOR SALE OVER-THE COUNTER MEDICATION LATER THAN EXPIRATION DATE ON THE LABEL.”                                 </span></p>
<p><span>“NYC Admin Code § 20-708 – STORE DID NOT CONSPICUOUSLY DISPLAY THE TOTAL SELLING PRICE, AT POINT OF DISPLAY, FOR ITEM.”                                                              </span></p>
<p><span>“6 RCNY § 5-70(a) – NO PRICE LIST FOR SERVICES DISPLAYED”                                            </span></p>
<p><span>“6 RCNY § 5-70(a) – PRICE LIST NOT DISPLAYED CONSPICUOUSLY”                                          </span><span> </span></p>
<p>I parsed the first part which describes the rule and is before the dash of the description, then counted the number of charges vs each categorical description.  I would have liked to generalize about what each rule was, and turn this into a category as well.  However, I realized that would skew the analysis since for some categories, it’s difficult to conclude what the general description might be.  I also tried to find a source about the rules which I could then cross reference, but only found <a rel="nofollow" href="http://library.amlegal.com/nxt/gateway.dll/New%20York/admin/newyorkcityadministrativecode?f=templates$fn=default.htm$3.0$vid=amlegal:newyork_ny" target="_blank">this searchable document</a> which is difficult to scrape data from.</p>
<h3>Who are the stakeholders and what can we learn?</h3>
<p>Are you an activist citizen who is concerned about what regulations your local businesses are required to follow?  Or perhaps a policy maker who is interested in the applicability of the current laws and rules that protect consumers?  Would it be surprising to discover that most of the charges fall under just a few categories?  That industries such as pharmacies and tobacco retailers get enforced more heavily?  Or that more charges were brought against boroughs which have stronger retail business climates?  In analyzing the data, I discovered these kinds of trends.</p>
<p><a rel="nofollow" href="https://i1.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/02/Screen-Shot-2018-02-04-at-11.14.51-PM.png" target="_blank"><img sizes="(max-width: 1024px) 100vw, 1024px" src="https://i1.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/02/Screen-Shot-2018-02-04-at-11.14.51-PM-1024x377.png?w=450" alt="" class="wp-image-28317" data-recalc-dims="1"></a></p>
<p> </p>
<p><a rel="nofollow" href="https://i0.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/02/Screen-Shot-2018-02-04-at-11.18.46-PM.png" target="_blank"><img sizes="(max-width: 979px) 100vw, 979px" src="https://i0.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/02/Screen-Shot-2018-02-04-at-11.18.46-PM.png?w=450" alt="" class="wp-image-28318" data-recalc-dims="1"></a></p>
<p> </p>
<h3>The App</h3>
<p>More insights can be garnered by visiting the <a rel="nofollow" href="https://zipporah.shinyapps.io/datavis/" target="_blank">app</a> and manipulating the parameters.  I chose a very simple design and intended that the parameters could be applied to multiple plot types which can then be viewed by navigating through the tabs.  I left it in the user’s control to decide how many “top” industries or charge types they were interested in analyzing.</p>
<p>I also provided a word cloud to highlight what the most dominant words in the text of the charge descriptions.  I used some R packages to remove the extraneous English words and additionally, I removed words like “near”, “required” and “upon” which don’t relay any meaning.</p>
<h3><a rel="nofollow" href="https://i1.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/02/Screen-Shot-2018-02-04-at-11.26.08-PM.png" target="_blank"><img sizes="(max-width: 381px) 100vw, 381px" src="https://i1.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/02/Screen-Shot-2018-02-04-at-11.26.08-PM.png?resize=381%2C310" alt="" width="381" class="wp-image-28332" data-recalc-dims="1" height="310"></a>The Code</h3>
<p>And now without further ado, please feel free to peruse my code.</p>
<p>View the code on <a rel="nofollow" href="https://gist.github.com/ZipporahPolinskyNagel/d6fe5726451a621e3a11f62757e02139" target="_blank">Gist</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://nycdatascience.com/blog/student-works/r-visualization/department-of-consumer-affairs-charges/"> R – NYC Data Science Academy Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/SixAHenQWvE" height="1"></a></div>