ebook img

Interactive Web-Based Data Visualization with R, plotly, and shiny PDF

449 Pages·2020·104.208 MB·\449
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Interactive Web-Based Data Visualization with R, plotly, and shiny

Interactive Web-Based Data Visualization with R, plotly, and shiny Chapman & Hall/CRC The R Series Series Editors John M. Chambers, Department of Statistics, Stanford University, California, USA Torsten Hothorn, Division of Biostatistics, University of Zurich, Switzerland Duncan Temple Lang, Department of Statistics, University of California, Davis, USA Hadley Wickham, RStudio, Boston, Massachusetts, USA Recently Published Titles Analyzing Baseball Data with R, Second Edition Max Marchi, Jim Albert, Benjamin S. Baumer Spatio-Temporal Statistics with R Christopher K. Wikle, Andrew Zammit-Mangion, and Noel Cressie Statistical Computing with R, Second Edition Maria L. Rizzo Geocomputation with R Robin Lovelace, Jakub Nowosad, Jannes Muenchow Advanced R, Second Edition Hadley Wickham Dose Response Analysis Using R Christian Ritz, Signe Marie Jensen, Daniel Gerhard, Jens Carl Streibig Distributions for Modelling Location, Scale, and Shape Using GAMLSS in R Robert A. Rigby , Mikis D. Stasinopoulos, Gillian Z. Heller and Fernanda De Bastiani Hands-On Machine Learning with R Bradley Boehmke and Brandon Greenwell Statistical Inference via Data Science A ModernDive into R and the Tidyverse Chester Ismay and Albert Y. Kim Reproducible Research with R and RStudio, Third Edition Christopher Gandrud Interactive Web-Based Data Visualization with R, plotly, and shiny Carson Sievert For more information about this series, please visit: https://www.crcpress.com/ Chapman--HallCRC-The-R-Series/book-series/CRCTHERSER Interactive Web-Based Data Visualization with R, plotly, and shiny Carson Sievert CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2020 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Printed on acid-free paper International Standard Book Number-13: 978-1-138-33145-7 (Paperback) International Standard Book Number-13: 978-1-138-33149-5 (Hardback) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com For the R community: Your kindness and generosity are truly inspiring. Contents 1 Introduction 1 1.1 Why interactive web graphics from R? . . . . . . . . . 1 1.2 Whatyouwilllearn . . . . . . . . . . . . . . . . . . 7 1.3 Whatyouwon’tlearn(muchof) . . . . . . . . . . . . 12 1.3.1 Webtechnologies . . . . . . . . . . . . . . . 12 1.3.2 d3js . . . . . . . . . . . . . . . . . . . . . . . 12 1.3.3 ggplot2 . . . . . . . . . . . . . . . . . . . . . 12 1.3.4 Graphicaldataanalysis . . . . . . . . . . . . 13 1.3.5 Data visualization best practices . . . . . . . 13 1.4 Prerequisites . . . . . . . . . . . . . . . . . . . . . . 13 1.5 Runcodeexamples . . . . . . . . . . . . . . . . . . . 14 1.6 Gettinghelpandlearningmore . . . . . . . . . . . . 14 1.7 Acknowledgments . . . . . . . . . . . . . . . . . . . 15 1.8 Colophon . . . . . . . . . . . . . . . . . . . . . . . . 16 I Creating views 21 2 Overview 23 2.1 Intro to plot_ly() . . . . . . . . . . . . . . . . . . . . 23 2.2 Introtoplotly.js . . . . . . . . . . . . . . . . . . . . 32 2.3 Intro to ggplotly() . . . . . . . . . . . . . . . . . . . 36 3 Scattered foundations 45 3.1 Markers . . . . . . . . . . . . . . . . . . . . . . . . . 51 3.1.1 Alphablending . . . . . . . . . . . . . . . . . 52 3.1.2 Colors . . . . . . . . . . . . . . . . . . . . . . 53 3.1.3 Symbols . . . . . . . . . . . . . . . . . . . . . 56 3.1.4 Strokeandspan . . . . . . . . . . . . . . . . 59 3.1.5 Size . . . . . . . . . . . . . . . . . . . . . . . 60 3.1.6 Dotplotsanderrorbars . . . . . . . . . . . . 62 vii viii Contents 3.2 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.2.1 Linetypes . . . . . . . . . . . . . . . . . . . . 64 3.2.2 Segments . . . . . . . . . . . . . . . . . . . . 66 3.2.3 Densityplots . . . . . . . . . . . . . . . . . . 73 3.2.4 Parallelcoordinates . . . . . . . . . . . . . . 74 3.3 Polygons . . . . . . . . . . . . . . . . . . . . . . . . 77 3.3.1 Ribbons . . . . . . . . . . . . . . . . . . . . . 79 4 Maps 81 4.1 Integratedmaps . . . . . . . . . . . . . . . . . . . . 82 4.1.1 Overview . . . . . . . . . . . . . . . . . . . . 82 4.1.2 Choropleths . . . . . . . . . . . . . . . . . . 91 4.2 Custommaps . . . . . . . . . . . . . . . . . . . . . . 94 4.2.1 Simplefeatures(sf) . . . . . . . . . . . . . . 94 4.2.2 Cartograms . . . . . . . . . . . . . . . . . . . 101 5 Bars and histograms 107 5.1 Multiple numeric distributions . . . . . . . . . . . . 110 5.2 Multiple discrete distributions . . . . . . . . . . . . 111 6 Boxplots 115 7 2D frequencies 119 7.1 Rectangular binning in plotly.js . . . . . . . . . . . . 119 7.2 RectangularbinninginR . . . . . . . . . . . . . . . 120 7.3 Categoricalaxes . . . . . . . . . . . . . . . . . . . . 122 8 3D charts 125 8.1 Markers . . . . . . . . . . . . . . . . . . . . . . . . . 125 8.2 Paths . . . . . . . . . . . . . . . . . . . . . . . . . . 126 8.3 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . 127 8.4 Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 8.5 Surfaces . . . . . . . . . . . . . . . . . . . . . . . . 130 II Publishing views 133 9 Introduction 135 10 Saving and embedding HTML 137 Contents ix 11 Exporting static images 141 11.1 Withcode . . . . . . . . . . . . . . . . . . . . . . . . 141 11.2 Fromabrowser . . . . . . . . . . . . . . . . . . . . 142 11.3 Sizingexports . . . . . . . . . . . . . . . . . . . . . 144 12 Editing views for publishing 145 III Combining multiple views 149 13 Arranging views 151 13.1 Arrangingplotlyobjects . . . . . . . . . . . . . . . . 151 13.1.1 Recursivesubplots . . . . . . . . . . . . . . . 155 13.1.2 Other approaches and applications . . . . . . 158 13.2 Arranginghtmlwidgets . . . . . . . . . . . . . . . . 164 13.2.1 flexdashboard . . . . . . . . . . . . . . . . . 165 13.2.2 Bootstrapgridlayout . . . . . . . . . . . . . 166 13.2.3 CSSflexbox . . . . . . . . . . . . . . . . . . . 167 13.3 Arrangingmanyviews . . . . . . . . . . . . . . . . . 169 14 Animating views 173 14.1 AnimationAPI . . . . . . . . . . . . . . . . . . . . . 173 14.2 Animationsupport . . . . . . . . . . . . . . . . . . . 177 IV Linking multiple views 183 15 Introduction 185 16 Client-side linking 189 16.1 Graphicalqueries . . . . . . . . . . . . . . . . . . . 189 16.2 Highlight versus filter events . . . . . . . . . . . . . 198 16.3 Linkinganimatedviews . . . . . . . . . . . . . . . . 204 16.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . 208 16.4.1 Querying faceted charts . . . . . . . . . . . . 208 16.4.2 Statisticalqueries . . . . . . . . . . . . . . . 214 16.4.3 Statistical queries with ggplotly() . . . . . . . 219 16.4.4 Geo-spatialqueries . . . . . . . . . . . . . . . 222 16.4.5 Linking with other htmlwidgets . . . . . . . . 226

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.