Styling ‘parallelPlot’

library(parallelPlot)

This text was originally published on the IFPEN forum.

Someone asked me for help styling a parallelPlot using the cssRules argument. In his case, he would like to hide the slider at the top of the chart.

parallelPlot(iris)

Let’s see how to find the solution following three steps.

Step 1 - Find which CSS rule to use

When we open a parallelPlot from a R console, it’s in fact a HTML page which is created.

HTML provides the fundamental building blocks for structuring Web documents and apps.

CSS is used to describe the appearance of Web documents and apps.

https://developer.mozilla.org/en-US/docs/Web

To find which CSS rule to use, we can rely on a search engine. The main keyword to use is css. Searching “css hide element”, the first result points to:

https://developer.mozilla.org/en-US/docs/Web/CSS/visibility

Thanks to the “Try it” section, the interesting option seems to be visibility: hidden.

Step 2 - Make some tests to determine where to apply the CSS rule

Step 3 - Write a CSS code to use as cssRules argument

CSS is a rule-based language — you define the rules by specifying groups of styles that should be applied to particular elements or groups of elements on your web page.

To learn more about CSS, see https://developer.mozilla.org/en/docs/Learn/CSS/First_steps

The cssRules argument expects a list of CSS rules. A CSS rule has two parts:

So, in a R console, we can try:

parallelPlot(iris, cssRules = list("g" = "visibility: hidden"))

But doing so, we hide to many elements, the displayed graph appears empty, all white. We need to use a more discriminating selector by specifying the class of the targeted group. To specify a class, the operator is the dot (to see the list of existing operators: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors).

In a R console, we can try:

parallelPlot(iris, cssRules = list("g.slider" = "visibility: hidden"))

Bingo!

This time, only the slider is hidden, while the graph itself is clearly visible.