Giter VIP home page Giter VIP logo

sciscales's Introduction

sciscales

The sciscales package provides convenient functions to convert ggplot2 axis labels, annotations, legend labels, etc. into formatted scientific notation. The output format is flexible, with several options included to allow customization of the formatted numbers.

Installation

You can install the development version of sciscales from GitHub with:

# install.packages("devtools")
devtools::install_github("christyray/sciscales")

Examples

ggplot2โ€™s default formatting for large numbers is to print them plainly with no formatting, which can be hard to read or unsightly for very large numbers.

The scales package includes the label_scientific() function, which formats large numbers in the e+00 notation. This can be much clearer than plain numbers, but may not be the desired formatting for a polished figure.

The sciscales package includes the label_sci() function to convert large numbers into formatted scientific notation. The label_sci() function can be passed to the labels argument of a scale_*() function to auto-format the label numbers.

library(ggplot2)
library(scales)
library(sciscales)
library(patchwork)

p <- ggplot(economics, aes(x = date, y = pop)) +
  geom_line() +
  labs(x = "Date", y = "Population")

p_ggplot <- p + ggtitle("ggplot2")
p_scales <- p + scale_y_continuous(labels = label_scientific()) + ggtitle("scales")
p_sciscales <- p + scale_y_continuous(labels = label_sci()) + ggtitle("sciscales")

p_ggplot + p_scales + p_sciscales

Additional arguments to label_sci() allow more control over the appearance of the formatted numbers, such as whether to include trailing zeros:

p + scale_y_continuous(labels = label_sci(trailing = FALSE))

sciscales's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.