# Scatter plot
library(plotly)
set.seed(123)
x <- rnorm(1000)
y <- rchisq(1000, df = 1, ncp = 0)
color <- sample(LETTERS[1:5], size = 1000, replace = T)
size <- sample(1:5, size = 1000, replace = T)
ds <- data.frame(x, y, color, size)
p <- plot_ly(ds, x = ~x, y = ~y, color = ~color, size = ~size) %>%
layout(title = "Scatter plot in")
embed_notebook(p)
Apart from plots and figures, tables and text output can shown as well. Just like in R-Markdown.
# Filled line Chart
library(plotly)
library(PerformanceAnalytics)
#Load data
data(managers)
# Convert to data.frame
managers.df <- as.data.frame(managers)
managers.df$Dates <- index(managers)
# See first few rows
head(managers.df)
# Plot
p <- plot_ly(managers.df, x = ~Dates, y = ~HAM1, name = "Manager 1") %>% add_lines()
layout(title = "Time Series plot")
embed_notebook(p)
HAM1 | HAM2 | HAM3 | HAM4 | HAM5 | HAM6 | EDHEC LS EQ | SP500 TR | US 10Y TR | US 3m TR | Dates | |
---|---|---|---|---|---|---|---|---|---|---|---|
1996-01-31 | 0.0074 | NA | 0.0349 | 0.0222 | NA | NA | NA | 0.034 | 0.0038 | 0.00456 | 1996-01-31 |
1996-02-29 | 0.0193 | NA | 0.0351 | 0.0195 | NA | NA | NA | 0.0093 | -0.03532 | 0.00398 | 1996-02-29 |
1996-03-31 | 0.0155 | NA | 0.0258 | -0.0098 | NA | NA | NA | 0.0096 | -0.01057 | 0.00371 | 1996-03-31 |
1996-04-30 | -0.0091 | NA | 0.0449 | 0.0236 | NA | NA | NA | 0.0147 | -0.01739 | 0.00428 | 1996-04-30 |
1996-05-31 | 0.0076 | NA | 0.0353 | 0.0028 | NA | NA | NA | 0.0258 | -0.00543 | 0.00443 | 1996-05-31 |
1996-06-30 | -0.0039 | NA | -0.0303 | -0.0019 | NA | NA | NA | 0.0038 | 0.01507 | 0.00412 | 1996-06-30 |
# Heat map
library(plotly)
library(mlbench)
# Get Sonar data
data(Sonar)
# Use only numeric data
rock <- as.matrix(subset(Sonar, Class == "R")[,1:59])
mine <- as.matrix(subset(Sonar, Class == "M")[,1:59])
# For rocks
p1 <- plot_ly(z = rock, type = "heatmap", showscale = F)
# For mines
p2 <- plot_ly(z = mine, type = "heatmap", name = "test") %>%
layout(title = "Mine vs Rock")
# Plot together
p3 <- subplot(p1, p2)
embed_notebook(p3)