<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/plotting-app-for-ggplot2-part-2/"></div></div><div><a data-url="http://www.r-bloggers.com/plotting-app-for-ggplot2-part-2/" data-counturl="http://www.r-bloggers.com/plotting-app-for-ggplot2-part-2/" data-count="horizontal" data-text="Plotting App for ggplot2 (Part 2)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://datascienceplus.com/plotting-app-for-ggplot2-part-2/"> DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Through this post, I would like to provide an update to my plotting app, which I first blogged about <a target="_blank" href="http://datascienceplus.com/plotting-app-for-ggplot2/">here</a>.<br>
The app is available as part of my package <code> RtutoR</code>, which is published on CRAN.(The app is also hosted at <a target="_blank" rel="nofollow" href="https://nairanup.shinyapps.io/PlotterApp/">shinyapps.io</a>. However, unlike the package version, you would not be able to use your own dataset with this hosted version) </p>
<p>The plotting app was developed to provide an automated interface for generating plots using the ggplot2 package. At the end of this post, is a video demo on how to use the app, with the demo specifically focusing on the new features and functionalities that have been added to this version of the app.</p>
<p>I also provide below a brief overview of these new functionalities:</p>
<h3> Faceting </h3>
<p>Faceting is a very useful feature in ggplot which allows us to split our data by one or more variables, and generate a plot on each subset of the data.<br>
For e.g, the code below will generate a scatter plot depicting the relationship between the price of the diamond and it’s carat <b>for each cut of the diamond </b></p>
<pre> ggplot(diamonds) + geom_point(aes(x=price,y=carat)) + facet_wrap(~cut) </pre>
<p>Note that <code> facet_grid </code> does something very similar; It primarily differs in the way the resulting plots are laid out and arranged on the grid (with a few other subtle differences, for e.g. refer to the Stack Overflow discussion <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/20457905/whats-the-difference-between-facet-wrap-and-facet-grid-in-ggplot2">here</a>)</p>
<p>Currently, the plotting app only supports facet_wrap with one variable.</p>
<h3> Color palette </h3>
<p>When a color (or fill) aesthetic is mapped to a variable, ggplot2 uses a default coloring scheme to color the different levels of the variable (in the case of categorical variables) or uses a color gradient scheme to represent the range of values (in case of continuous variables). ggplot2 provides various other color schemes to choose from, if you are not happy with the default coloring scheme.</p>
<p>For discrete variables, an excellent choice is the brewer scale (which is taken from the RColorBrewer package), which is what the plotting app supports. There are more than 30 different palettes to choose from, divided into 3 color schemes – Sequential, Qualitative and Diverging.</p>
<p>For continuous variables, <code> scale_color_gradient </code> provides an easy and convenient way to alter the color scheme. For e.g, the code below plots the relationship between price and carat, however, instead of using the default coloring scheme for price, the price is now colored from yellow (for low values) to red (high values)</p>
<pre> ggplot(diamonds) + geom_point(aes(price,carat,col=price)) + scale_color_gradient(low=&quot;yellow&quot;,high=&quot;red&quot;) </pre>
<h3> Axis range control </h3>
<p>Allowing the users to manually alter the axis range is another enhancement in this version of the plotting app. This feature can be used, for instance, to remove outliers from your plot or to help you zoom in on a specific section of the plot.</p>
<p>For e.g. let’s generate a box plot depicting the price distribution for each cut of the diamond:</p>
<pre> ggplot(diamonds) + geom_box(aes(x=cut,y=price)) </pre>
<p>If you are really interested in just analyzing the Inter Quartile distribution for different cuts, you can limit the length of the tail as follows:</p>
<pre> ggplot(diamonds) + geom_boxplot(aes(x=cut,y=price)) + ylim(c(0,10000)) </pre>
<p>By limiting the length of the tails, the plot zooms out providing a better comparison of the price distribution for different cuts.</p>
<p>(The plotting app provides a slider input for manually adjusting the axis ranges – The slider ranges are dynamic and is based on the minimum and maximum values for the selected variable)</p>
<h3> Color Picker </h3>
<p>Previous version of the app provided a color drop-down for selecting colors, for manually setting the color/fill aesthetic. The dropdown had more than 600 different colors to choose from (generated using the <code> colors() </code> function in R)<br>
However, the new version of the app, replaces the color dropdown with a color picker (available as part of the <code> shinyjs </code> package). Color picker provides a far more more intuitive and convenient way to choose a color of your choice (The underlying code which is displayed on the app, will also provide the hex code for the selected color). </p>
<p>Hope you find this useful and check <a target="_blank" rel="nofollow" href="https://github.com/anup50695/RtutoR">my github account</a>.</p>
<ul>
<li><a target="_blank" href="https://www.youtube.com/watch?v=xgZ4bpEZX4g">Plotting App for ggplot2 (PART 2)</a></li>
</ul>
<p><strong>
<p>Related Post</p>
<p>
<ol>
<li><a title="Permanent Link toMastering R plot – Part 3: Outer margins" target="_blank" rel="bookmark" href="http://datascienceplus.com/mastering-r-plot-part-3-outer-margins/">Mastering R plot – Part 3: Outer margins</a></li>
<li><a title="Permanent Link toInteractive plotting with rbokeh" target="_blank" rel="bookmark" href="http://datascienceplus.com/interactive-plotting-with-rbokeh/">Interactive plotting with rbokeh</a></li>
<li><a title="Permanent Link toMastering R plot – Part 2: Axis" target="_blank" rel="bookmark" href="http://datascienceplus.com/mastering-r-plot-part-2-axis/">Mastering R plot – Part 2: Axis</a></li>
<li><a title="Permanent Link toHow to create a Twitter Sentiment Analysis using R and Shiny" target="_blank" rel="bookmark" href="http://datascienceplus.com/how-to-create-a-twitter-sentiment-analysis-using-r-and-shiny/">How to create a Twitter Sentiment Analysis using R and Shiny</a></li>
<li><a title="Permanent Link toVisualizing MLS Player Salaries with ggplot2" target="_blank" rel="bookmark" href="http://datascienceplus.com/visualizing-mls-player-salaries/">Visualizing MLS Player Salaries with ggplot2</a></li>
</ol></strong>
<div>
<a target="_blank" href="http://feeds.feedburner.com/~ff/datascienceplus?a=N5BpWPcWQSs:I1XEBRkzxUY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/datascienceplus?i=N5BpWPcWQSs:I1XEBRkzxUY:D7DqB2pKExk" border="0"></a> <a target="_blank" href="http://feeds.feedburner.com/~ff/datascienceplus?a=N5BpWPcWQSs:I1XEBRkzxUY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/datascienceplus?d=qj6IDK7rITs" border="0"></a> <a target="_blank" href="http://feeds.feedburner.com/~ff/datascienceplus?a=N5BpWPcWQSs:I1XEBRkzxUY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/datascienceplus?d=yIl2AUoC8zA" border="0"></a>
</div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/plotting-app-for-ggplot2-part-2/"></div></div><div><a data-url="http://www.r-bloggers.com/plotting-app-for-ggplot2-part-2/" data-counturl="http://www.r-bloggers.com/plotting-app-for-ggplot2-part-2/" data-count="vertical" data-text="Plotting App for ggplot2 (Part 2)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://datascienceplus.com/plotting-app-for-ggplot2-part-2/"> DataScience+</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/s3qnDYKtb-k"></a></div>