Set Chart Area Background Color in Rcharts/Slidify/Nvd3

Set chart area background color in rCharts/slidify/nvd3

As indicated in my comment, a quick fix to get a white background is to add the following lines to your Rmd file

<style>iframe{background-color: white}</style>

Render rCharts in slides from Slidify

All instructions below assume that you have the dev branch of the packages installed (slidify, slidifyLibraries and rCharts). You can accomplish this using install_github.

pkgs <- c("slidify", "slidifyLibraries", "rCharts")
devtools::install_github(pkgs, "ramnathv", ref = "dev")

There are two ways to include an rCharts viz in your slidify document, and the deck below illustrates both ways. If you print a plot in a code chunk, as you would do so in the R console, slidify automatically detects that you are running it in a knitr session and as a result save the resulting html to an iframe and embed it in the deck. Alternately, you can specify the chart inline, in which case you have to use n1$show("inline") and also include ext_widgets: {rCharts: libraries/nvd3} in your YAML front matter.

The iframe method is the default and the recommended method to avoid conflicts between various javascript files and css. The inline method does work well for several rCharts libraries, but make sure to check before you use.

---
title : rCharts Integration
ext_widgets : {rCharts: libraries/nvd3}
mode: selfcontained
---

## NVD3 Plot Inline

```{r nvd3plot, results = 'asis', comment = NA, message = F, echo = F}
require(rCharts)
n1 <- nPlot(mpg ~ wt, data = mtcars, type = 'scatterChart')
n1$show('inline')
```

---

## NVD3 Plot Iframe

```{r nvd3plot2, results = 'asis', comment = NA, message = F, echo = F}
require(rCharts)
n1 <- nPlot(mpg ~ wt, data = mtcars, type = 'scatterChart')
n1
```

R. doing cool plot, no X labels

To get the labels like "Jan/15" you need to pass the dates through strptime to get them into time since epoch and then through strftime to get them formatted accordingly. No need to multiply the dates by 1000 etc.
For your case, let me know if the following works out. You can read more about the formatting of dates by doing ?strptime and ?strftime in R REPL.

x$dmy = strftime(strptime(x$YYYYMM, format = "%m/%d/%Y"), format = "%b/%y")
myplot <- hPlot(COUNT ~ dmy, data=x, type="line")
myplot

Not sure how to change the background color in rcharts



Related Topics



Leave a reply



Submit