R Data Visualization Recipes by Vitor Bianchi Lanzetta
Author:Vitor Bianchi Lanzetta [Vitor Bianchi Lanzetta]
Language: eng
Format: epub
Tags: COM089000 - COMPUTERS / Data Visualization, COM062000 - COMPUTERS / Data Modeling and Design, COM018000 - COMPUTERS / Data Processing
Publisher: Packt
Published: 2017-11-21T07:07:49+00:00
How it works...
Step 1 in takes care of plotting stacked proportional bars using ggplot2. It demands only little coding and most of it looks like Recipe Creating simple stacked bars, except for the position argument in the geom_bar() function. This argument is now inputted with the string 'fill'. A great deal of geom_*() functions do accept 'fill' as an input to position argument. This input usually makes the geometry about proportions.
Argument position makes very easy to ask for proportions using ggplot2. Improvement can be delivered by Hadley's scale package. If you have already got it installed, there is no need to restart your R Session, but if that's not the case, do so and run the following code to improve the y-axis labels:
> if( !require(scales)){ install.packages('scales')}
> library(ggplot2)
> gg2_sal <- ggplot( data = car::Salaries, aes(x = rank))
> gg2_sal + geom_bar(position = 'fill', aes(fill = sex)) +
> scale_y_continuous(labels = scales::percent_format())
The resulting plot displays the y-axis labels in the percentage format. Changes like that are very useful, keep scales package nearby. Check the result in the following image (Figure 5.4):
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Access | Data Mining |
Data Modeling & Design | Data Processing |
Data Warehousing | MySQL |
Oracle | Other Databases |
Relational Databases | SQL |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8300)
Azure Data and AI Architect Handbook by Olivier Mertens & Breght Van Baelen(6741)
Building Statistical Models in Python by Huy Hoang Nguyen & Paul N Adams & Stuart J Miller(6716)
Serverless Machine Learning with Amazon Redshift ML by Debu Panda & Phil Bates & Bhanu Pittampally & Sumeet Joshi(6593)
Data Wrangling on AWS by Navnit Shukla | Sankar M | Sam Palani(6377)
Driving Data Quality with Data Contracts by Andrew Jones(6326)
Machine Learning Model Serving Patterns and Best Practices by Md Johirul Islam(6093)
Learning SQL by Alan Beaulieu(5995)
Weapons of Math Destruction by Cathy O'Neil(5779)
Big Data Analysis with Python by Ivan Marin(5363)
Data Engineering with dbt by Roberto Zagni(4361)
Solidity Programming Essentials by Ritesh Modi(4009)
Time Series Analysis with Python Cookbook by Tarek A. Atwan(3870)
Pandas Cookbook by Theodore Petrou(3578)
Blockchain Basics by Daniel Drescher(3294)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2905)
Feature Store for Machine Learning by Jayanth Kumar M J(2814)
Learn T-SQL Querying by Pam Lahoud & Pedro Lopes(2796)
Mastering Python for Finance by Unknown(2744)
