Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Probability
Views: 38
Kernel: R (R-Project)

Make sure to switch your kernel to R

Note: You can double-click your output to hide it, especially useful for a graph

next line resizes graphs to make them readable

library(repr) # Change plot size to 4 x 4 options(repr.plot.width=4, repr.plot.height=4)
curve(x^2,-5,5)
Image in a Jupyter notebook
curve(x^2, col='blue') curve(x^3, col='green',add=TRUE) curve(x^4, col='red',add=TRUE)
Image in a Jupyter notebook
library(ggplot2) library(plotly) set.seed(123) x <- rnorm(1000) y <- rchisq(1000, df = 1, ncp = 0) group <- sample(LETTERS[1:5], size = 1000, replace = T) size <- sample(1:5, size = 1000, replace = T) ds <- data.frame(x, y, group, size) p <- plot_ly(ds, type="scatter", x = x, y = y, mode = "markers", split = group, size = size) %>% layout(title = "Scatter Plot") embed_notebook(p)
Attaching package: ‘plotly’ The following object is masked from ‘package:ggplot2’: last_plot The following object is masked from ‘package:stats’: filter The following object is masked from ‘package:graphics’: layout
d <- diamonds[sample(nrow(diamonds), 1000), ] plot_ly(d, x = ~carat, y = ~price, color = ~carat, size = ~carat, text = ~paste("Clarity: ", clarity))
No trace type specified: Based on info supplied, a 'scatter' trace seems appropriate. Read more about this trace type -> https://plot.ly/r/reference/#scatter No scatter mode specifed: Setting the mode to markers Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode iopub data rate exceeded. The notebook server will temporarily stop sending iopub messages to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_data_rate_limit`.
p <- ggplot(data = d, aes(x = carat, y = price)) + geom_point(aes(text = paste("Clarity:", clarity))) + geom_smooth(aes(colour = cut, fill = cut)) + facet_wrap(~ cut)
Warning message: “Ignoring unknown aesthetics: text”
p
`geom_smooth()` using method = 'loess'
MIME type unknown not supported
Image in a Jupyter notebook
# Heatmap 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)
Image in a Jupyter notebook