GithubHelp home page GithubHelp logo

tkonopka / rcssplot Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 4.0 363 KB

R plots styled with css

Home Page: https://github.com/tkonopka/Rcssplot/wiki

License: GNU General Public License v2.0

R 100.00%
r visualization css data-science

rcssplot's Introduction

Rcssplot

Status codecov CRAN_Status_Badge

The Rcssplot package brings cascading style sheets to the R graphical environment. It provides a means to separate the aesthetics from data crunching in plots and charts.

Installation

The package can be installed from CRAN.

install.packages("Rcssplot")

Alternatively, it can be installed from this github repository via devtools.

library("devtools")
install_github("tkonopka/Rcssplot")

Using Rcssplot

After installation, the package can be loaded using the library command.

library("Rcssplot")

The vignette on CRAN provides an in-depth tutorial and the github wiki provides examples. As a minimal use-case, consider a barplot.

barplot(1:4, col="red", density=10, border="red")

Styling of the plot is incorporated within the function call. In the Rcssplot framework, these settings can be delegated to a cascading style sheet.

RcssDefaultStyle <- Rcss(text="barplot { col: red; border: red; density: 10 }")
barplot(1:4)

The style definitions are here provided as a string, but in practice, it is easier to edit them in a file in a text editor. The output of the final barplot command reproduces the styling above.

Compatibility with base graphics

From version 1.0, loading the package using library(Rcssplot) triggers messages from the R environment that the package masks some well-known functions from base graphics. The masked functions include plot, text, mtext, and many others. Thus, after the package is loaded, executing commands such as plot will be trigger Rcssplot rather than base graphics.

The masking functions are designed to mimic the originals. Thus, in many cases, existing code using base graphics should work as before. Some exceptions may appear, however, if existing code makes extensive use of positional arguments. As an example, consider the following.

x100 <- rnorm(100)
hist(x100, 10)

While this is valid in base graphics, it triggers an error under Rcssplot because the argument 10 carries meaning through its position in the function call, and not through a named argument or keyword. To avoid the error, the command can be adjusted with an argument name.

hist(x100, breaks=10)

Acknowledgments

Many thanks to the CRAN team and contributors: FrancoisGuillem, nfultz

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.