-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot-Scripts.R
More file actions
37 lines (34 loc) · 983 Bytes
/
Plot-Scripts.R
File metadata and controls
37 lines (34 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Scripts for easier plotting
# Nice plot of a function in plotly
plot_fct <- function(f, from = NULL, to = NULL, n = 101){
if (!("plotly" %in% installed.packages()[, "Package"])) {
install.packages(new.packages, repos = "http://cran.us.r-project.org")
}
library(plotly)
x <- seq(from, to, length.out = n)
tmp <- data.frame(x = x, y = f(x))
plot_ly(
tmp,
x = ~ x,
y = ~ y,
name = 'Plot of f',
type = 'scatter',
mode = 'lines'
)
}
# Nice plot of two vectors
plot_vec <- function(x = NULL, y = NULL, from = NULL, to = NULL, mode = 'markers'){
if (!("plotly" %in% installed.packages()[, "Package"])) {
install.packages(new.packages, repos = "http://cran.us.r-project.org")
}
library(plotly)
tmp_from <- ifelse(is.null(from), 1, from)
tmp_to <- ifelse(is.null(to), length(x), to)
plot_ly(
x = ~ x[tmp_from:tmp_to],
y = ~ y[tmp_from:tmp_to],
name = 'Plot of Y against X',
type = 'scatter',
mode = mode
)
}