Skip to content

Instantly share code, notes, and snippets.

@witwall
Created June 15, 2016 06:53
Show Gist options
  • Save witwall/5b7032de62f164ea700c321b9a1950d4 to your computer and use it in GitHub Desktop.
Save witwall/5b7032de62f164ea700c321b9a1950d4 to your computer and use it in GitHub Desktop.
### Sample knitr Doc
###Copy and paste all the code to http://shiny.alitrack.com/ace/03-knitr/
This is some markdown text. It may also have embedded R code
which will be executed.
```{r results="asis" ,echo=FALSE}
dat <- data.frame(
t = rep(0:23, each = 4),
var = rep(LETTERS[1:4], 4),
val = round(runif(4*24,0,50))
)
p8 <- nPlot(val ~ t, group = 'var', data = dat,
type = 'stackedAreaChart', id = 'chart'
)
p8
```
```{r results="asis"}
p1 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart')
p1$xAxis(axisLabel = 'Weight (in lb)')
p1
```
It can even include graphical elements.
```{r results="asis"}
hist(rnorm(100))
```
```{r results="asis"}
hair_eye = as.data.frame(HairEyeColor)
p2a <- nPlot(Freq ~ Hair, group = 'Eye',
data = hair_eye,
type = 'multiBarChart'
)
p2a$chart(color = c('brown', 'blue', '#594c26', 'green'))
p2a$addFilters("Sex")
p2a$set(dom = 'chart2', width = 600)
p2a
```
```{r results="asis"}
p3 <- nPlot(~ cyl, group = 'gear', data = mtcars, type = 'multiBarHorizontalChart')
p3$chart(showControls = F)
p3
```
```{r results="asis"}
p4 <- nPlot(~ cyl, data = mtcars, type = 'pieChart')
p4
```
```{r results="asis"}
p5 <- nPlot(~ cyl, data = mtcars, type = 'pieChart')
p5$chart(donut = TRUE)
p5
```
```{r results="asis"}
library(ggplot2)
data(economics, package = 'ggplot2')
p6 <- nPlot(uempmed ~ date, data = economics, type = 'lineChart')
p6
```
````{r results="asis"}
library(quantmod)
getSymbols("AAPL")
xts_to_df <- function(xt){
data.frame(
date = format(as.Date(index(xt)), '%Y-%m-%d'),
coredata(xt)
)
}
dat = xts_to_df(AAPL)
plotCalMap('date', 'AAPL.Adjusted',
data = dat,
domain = 'month',
legend = seq(500, 700, 40),
start = '2014-01-01',
itemName = '$$'
)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment