Skip to main content

ggplot2

Elegant Graphics for Data Analysis

  • Book
  • © 2009

Overview

  • Teaches how to create graphics in R using ggplot
  • Discusses the theoretical framework that underlies ggplot
  • Includes supplementary material: sn.pub/extras

Part of the book series: Use R! (USE R)

This is a preview of subscription content, log in via an institution to check access.

Access this book

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

eBook USD 54.99
Price excludes VAT (Canada)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

') var buybox = document.querySelector("[data-id=id_"+ timestamp +"]").parentNode var buyboxMaxSingleColumnWidth = 480 var now = new Date().getTime() var start = 1650956400000 var end = 1652338800000 var isMeasuringTime = now > start && now < end var campaignPricesMetricsGroup = initMetrics(start, end) var campaignPricesActive = campaignPricesMetricsGroup === "B" if (campaignPricesActive) { revealCampaignPriceVersion() } var priceNS = campaignPricesActive ? ".buying-option-price-campaign " : "" ;[].slice.call(buybox.querySelectorAll(".buying-option")).forEach(initCollapsibles) ;[].slice.call(buybox.querySelectorAll(".buying-option")).forEach(addMetrics) function initMetrics(start, end) { var metricsKey = "abMetricsCampaignPrices-v1" var campaignPricesMetricsGroup = "X" if (!window.localStorage || !window.fetch) return campaignPricesMetricsGroup if (!isMeasuringTime) { window.localStorage.removeItem(metricsKey) return "NONE" } try { var metricsValue = window.localStorage.getItem(metricsKey) campaignPricesMetricsGroup = metricsValue || randomDistribution(metricsKey) } catch (err) { console.log(err) } return campaignPricesMetricsGroup } function randomDistribution(metricsKey) { var randomGroup = Math.random() < 0.5 ? "A" : "B" window.localStorage.setItem(metricsKey, randomGroup) return randomGroup } function revealCampaignPriceVersion() { buybox.querySelector(".c-box").classList.add("campaign-prices") buybox.querySelectorAll(".buying-option-price-campaign").forEach(function (campaignPrice) { campaignPrice.removeAttribute("style") }) } function initCollapsibles(buyingOption, index) { var toggle = buyingOption.querySelector(priceNS + ".buying-option-price") buyingOption.classList.remove("expanded") var form = buyingOption.querySelector(".buying-option-form") var priceInfo = buyingOption.querySelector(priceNS + ".price-info") if (toggle && form && priceInfo) { toggle.setAttribute("role", "button") toggle.setAttribute("tabindex", "0") toggle.addEventListener("click", function (event) { var expandedBuyingOptions = buybox.querySelectorAll(".buying-option.expanded") var buyboxWidth = buybox.offsetWidth ;[].slice.call(expandedBuyingOptions).forEach(function(option) { if (buyboxWidth <= buyboxMaxSingleColumnWidth && option != buyingOption) { hideBuyingOption(option) } }) var expanded = toggle.getAttribute("aria-expanded") === "true" || false toggle.setAttribute("aria-expanded", !expanded) form.hidden = expanded if (!expanded) { buyingOption.classList.add("expanded") } else { buyingOption.classList.remove("expanded") } priceInfo.hidden = expanded }, false) } } function addMetrics(buyingOption) { setTimeout(function () { var collapsed = buybox.querySelector(".buying-option.expanded") === null var form = buyingOption.querySelector(".buying-option-form") var formAction = form.getAttribute("action") if (form) { var metricsAppendix = formAction.indexOf("?") ==! -1 ? "&" : "?" metricsAppendix += "discount=" + (buyingOption.querySelector(".buying-option-price-campaign").className.indexOf("discounted") !== -1).toString() metricsAppendix += "&metricsGroup=" + campaignPricesMetricsGroup metricsAppendix += "&collapsed=" + collapsed.toString() form.action = formAction + metricsAppendix } }, 1) } function hideBuyingOption(buyingOption) { var toggle = buyingOption.querySelector(".buying-option-price") var form = buyingOption.querySelector(".buying-option-form") var priceInfo = buyingOption.querySelector(".price-info") toggle.setAttribute("aria-expanded", false) form.hidden = true buyingOption.classList.remove("expanded") priceInfo.hidden = true } function initKeyControls() { document.addEventListener("keydown", function (event) { if (document.activeElement.classList.contains("buying-option-price") && (event.code === "Space" || event.code === "Enter")) { if (document.activeElement) { event.preventDefault() document.activeElement.click() } } }, false) } function initialStateOpen() { var buyboxWidth = buybox.offsetWidth var narrowBuyboxArea = buyboxWidth <= buyboxMaxSingleColumnWidth var allOptionsInitiallyCollapsed = buybox.className.indexOf("all-options-initially-collapsed") > -1 ;[].slice.call(buybox.querySelectorAll(".buying-option")).forEach(function (option, index) { var toggle = option.querySelector(priceNS + ".buying-option-price") var form = option.querySelector(".buying-option-form") var priceInfo = option.querySelector(priceNS + ".price-info") if (allOptionsInitiallyCollapsed || narrowBuyboxArea && index > 0) { toggle.setAttribute("aria-expanded", "false") form.hidden = "hidden" priceInfo.hidden = "hidden" } else { toggle.click() } }) } initialStateOpen() if (window.buyboxInitialised) return window.buyboxInitialised = true initKeyControls() if (window.fetch && isMeasuringTime) { var collapsed = buybox.querySelector(".buying-option.expanded") === null var metricsAppendix = "" metricsAppendix += "&discount=" + (buybox.querySelector(".buying-option-price-campaign").className.indexOf("discounted") !== -1).toString() metricsAppendix += "&metricsGroup=" + campaignPricesMetricsGroup metricsAppendix += "&collapsed=" + collapsed.toString() window.fetch("https://test-buckets.springer.com/log?v3&time=" + now + metricsAppendix) .then(function (res) { return res.text() }) .catch(function () { }) } })()

Other ways to access

Licence this eBook for your library

Institutional subscriptions

About this book

1. 1 Welcome to ggplot2 ggplot2 is an R package for producing statistical, or data, graphics, but it is unlike most other graphics packages because it has a deep underlying grammar. This grammar, based on the Grammar of Graphics (Wilkinson, 2005), is composed of a set of independent components that can be composed in many di?erent ways. This makesggplot2 very powerful, because you are not limited to a set of pre-speci?ed graphics, but you can create new graphics that are precisely tailored for your problem. This may sound overwhelming, but because there is a simple set of core principles and very few special cases, ggplot2 is also easy to learn (although it may take a little time to forget your preconceptions from other graphics tools). Practically,ggplot2 provides beautiful, hassle-free plots, that take care of ?ddly details like drawing legends. The plots can be built up iteratively and edited later. A carefully chosen set of defaults means that most of the time you can produce a publication-quality graphic in seconds, but if you do have special formatting requirements, a comprehensive theming system makes it easy to do what you want. Instead of spending time making your graph look pretty, you can focus on creating a graph that best reveals the messages in your data.

Similar content being viewed by others

Keywords

Table of contents (10 chapters)

Authors and Affiliations

  • Houston, U.S.A.

    Hadley Wickham

Bibliographic Information

Publish with us

Navigation

-