Los ejemplos son tomados de la página oficial de plotly, principalmente se obtienen algunos ejemplos gráficos de plotly
.
LibrerÃas
require(plotly)
require(knitr)
require(tidyr)
require(dplyr)
require(rjson)
require(igraph)
require(igraphdata)
require(jpeg)
require(EBImage)
require(geomorph)
require(scales)
require(anglr)
require(maptools)
data <- data.frame(journalist = c(75,70,75,5,10,10,20,10,15,10,20),
developer = c(25,10,20,60,80,90,70,20,5,10,10),
designer = c(0,20,5,35,10,0,10,70,80,80,70),
label = c('point 1','point 2','point 3','point 4','point 5','point 6',
'point 7','point 8','point 9','point 10','point 11'))
axis <- function(title) {
list(title = title,
titlefont = list(size = 20),
tickfont = list(size = 15),
tickcolor = 'rgba(0,0,0,0)',
ticklen = 5)
}
p <- data %>%
plot_ly() %>%
add_trace(type = 'scatterternary',
mode = 'markers',
a = ~journalist,
b = ~developer,
c = ~designer,
text = ~label,
marker = list(symbol = 100,
color = '#DB7365',
size = 14,
line = list('width' = 2))) %>%
layout(title = "Simple Ternary Plot with Markers",
ternary = list(sum = 100,
aaxis = axis('Journalist'),
baxis = axis('Developer'),
caxis = axis('Designer')))
p
data <- fromJSON(file="https://gist.githubusercontent.com/davenquinn/988167471993bc2ece29/raw/f38d9cb3dd86e315e237fde5d65e185c39c931c2/data.json")
colors = c('#8dd3c7','#ffffb3','#bebada','#fb8072','#80b1d3','#fdb462','#b3de69','#fccde5','#d9d9d9', '#bc80bd','#ccebc5','#ffed6f')
p <- plot_ly()
for (i in 1:length(data)) {
l = c()
m = c()
n = c()
for (j in 1:length(data[[i]])) {
l[[j]] <- data[[i]][[j]]$clay
m[[j]] <- data[[i]][[j]]$sand
n[[j]] <- data[[i]][[j]]$silt
}
p <- p %>%
add_trace(type = 'scatterternary',
a = l,
b = m,
c = n,
name = names(data[i]),
mode = 'lines',
line = list(color='#444'),
fill = 'toself',
fillcolor = colors[i],
showlegend = F) %>%
layout(title = "Simple Ternary Contour Plot in R",
ternary = list(sum = 100,
aaxis = list(title = "clay",
ticksuffix = "%",
min = 0.01,
linewidth = 2,
ticks = "outside"),
baxis = list(title = "sand",
ticksuffix = "%",
min = 0.01,
linewidth = 2,
ticks = "outside"),
caxis = list(title = "silt",
ticksuffix = "%",
min = 0.01,
linewidth = 2,
ticks = "outside")))
}
p
La bae de datos que se usa va en relación al social-network del club de karate de Zachary. El archivo de formato GML se puede recopilar desde aquÃ.
data(karate, package="igraphdata")
G <- upgrade_graph(karate)
L <- layout.circle(G)
## Create Vertices and Edges
vs <- V(G)
es <- as.data.frame(get.edgelist(G))
Nv <- length(vs)
Ne <- length(es[1]$V1)
## Create Nodes
Xn <- L[,1]
Yn <- L[,2]
## Creates Edges
edge_shapes <- list()
for(i in 1:Ne) {
v0 <- es[i,]$V1
v1 <- es[i,]$V2
edge_shape = list(type = "line",
line = list(color = "#030303", width = 0.3),
x0 = Xn[v0],
y0 = Yn[v0],
x1 = Xn[v1],
y1 = Yn[v1])
edge_shapes[[i]] <- edge_shape
}
network <- plot_ly(x = ~Xn,
y = ~Yn,
mode = "markers",
text = vs$label,
hoverinfo = "text") %>%
layout(title = 'Karate Network',
shapes = edge_shapes,
xaxis = list(title = "",
showgrid = FALSE,
showticklabels = FALSE,
zeroline = FALSE),
yaxis = list(title = "",
showgrid = FALSE,
showticklabels = FALSE,
zeroline = FALSE))
network
p <- plot_ly(type = 'parcoords',
line = list(color = 'blue'),
dimensions = list(list(range = c(1,5),
constraintrange = c(1,2),
label = 'A',
values = c(1,4)),
list(range = c(1,5),
tickvals = c(1.5,3,4.5),
label = 'B',
values = c(3,1.5)),
list(range = c(1,5),
tickvals = c(1,2,4,5),
label = 'C',
values = c(2,4),
ticktext = c('text 1', 'text 2', 'text 3', 'text 4')),
list(range = c(1,5),
label = 'D',
values = c(4,2))))
p
data <- read.csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv")
p <- data %>%
plot_ly(type = 'parcoords',
line = list(color = ~species_id,
colorscale = list(c(0,'red'),c(0.5,'green'),c(1,'blue'))),
dimensions = list(list(range = c(2,4.5),
label = 'Sepal Width',
values = ~sepal_width),
list(range = c(4,8),
constraintrange = c(5,6),
label = 'Sepal Length',
values = ~sepal_length),
list(range = c(0,2.5),
label = 'Petal Width',
values = ~petal_width),
list(range = c(1,7),
label = 'Petal Length',
values = ~petal_length)))
p
data <- read.csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/parcoords_data.csv")
p <- data %>%
plot_ly(width = 1000, height = 600) %>%
add_trace(type = 'parcoords',
line = list(color = ~colorVal,
colorscale = 'Jet',
showscale = TRUE,
reversescale = TRUE,
cmin = -4000,
cmax = -100),
dimensions = list(list(range = c(~min(blockHeight),~max(blockHeight)),
constraintrange = c(100000,150000),
label = 'Block Height',
values = ~blockHeight),
list(range = c(~min(blockWidth),~max(blockWidth)),
label = 'Block Width',
values = ~blockWidth),
list(tickvals = c(0,0.5,1,2,3),
ticktext = c('A','AB','B','Y','Z'),
label = 'Cyclinder Material',
values = ~cycMaterial),
list(range = c(-1,4),
tickvals = c(0,1,2,3),
label = 'Block Material',
values = ~blockMaterial),
list(range = c(~min(totalWeight),~max(totalWeight)),
visible = TRUE,
label = 'Total Weight',
values = ~totalWeight),
list(range = c(~min(assemblyPW),~max(assemblyPW)),
label = 'Assembly Penalty Weight',
values = ~assemblyPW),
list(range = c(~min(HstW),~max(HstW)),
label = 'Height st Width',
values = ~HstW),
list(range = c(~min(minHW),~max(minHW)),
label = 'Min Height Width',
values = ~minHW),
list(range = c(~min(minWD),~max(minWD)),
label = 'Min Width Diameter',
values = ~minWD),
list(range = c(~min(rfBlock),~max(rfBlock)),
label = 'RF Block',
values = ~rfBlock)))
p
Para establecer las coordenadas \(x\) e \(y\), se usan los atributos \(x\) e \(y\) . Si se omiten los valores de las coordenadas \(x\), se creará un cheater plot.
Para guardar los valores de los parámetros, se utilizan los atributos \(a\) y \(b\).
Se utiliza la listas de aaxis
o baxis
para realizar cambios en los ejes.
p <- plot_ly(type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9),
baxis = list(tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9))
p
p <- plot_ly(type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9,
minorgridwidth = 0.6,
minorgridcolor = 'white',
gridcolor = 'white',
color = 'white'),
baxis = list(tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9,
minorgridwidth = 0.6,
gridcolor = 'white',
minorgridcolor = 'white',
color = 'white')) %>%
layout(plot_bgcolor = 'black',
paper_bgcolor = 'black',
xaxis = list(showgrid = F, showticklabels = F),
yaxis = list(showgrid = F, showticklabels = F))
p
p <- plot_ly(type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9),
baxis = list(tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9))
p
p <- plot_ly(type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9),
baxis = list(tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9)) %>%
add_trace(type = 'scattercarpet',
a = c(4, 4.5, 5, 6),
b = c(2.5, 2.5, 2.5, 2.5),
line = list(shape = 'spline',
smoothing = 1,
color = 'blue'),
marker = list(color = "blue"))
p
p <- plot_ly() %>%
add_trace(type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9),
baxis = list(tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9)) %>%
add_trace(type = 'scattercarpet',
a = c(4, 4.5, 5, 6),
b = c(2.5, 2.5, 2.5, 2.5),
mode = 'markers+lines',
line = list(shape = 'spline',
smoothing = 1,
color = "blue"),
marker = list(color = "blue")) %>%
add_trace(type = 'scattercarpet',
a = c(4, 4.5, 5, 6),
b = c(1.5, 1.5, 1.5, 1.5),
mode = 'lines',
line = list(shape = 'spline',
smoothing = 1,
color = "green")) %>%
add_trace(type = 'scattercarpet',
a = c(5, 5, 5, 5),
b = c(1, 1.5, 2, 3),
mode = 'markers',
marker = list(color = "red",
size = c(0,0,20,0))) %>%
add_trace(type = 'scattercarpet',
a = c(4.5, 4.5, 4.5, 4.5),
b = c(1, 1.5, 2, 3),
mode = 'markers',
marker = list(color = "black",
size = c(0,0,30,0)))
p
p <- plot_ly() %>%
add_trace(type = 'carpet',
a = c(0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3),
b = c(4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6),
x = c(2, 3, 4, 5, 2.2, 3.1, 4.1, 5.1, 1.5, 2.5, 3.5, 4.5),
y = c(1, 1.4, 1.6, 1.75, 2, 2.5, 2.7, 2.75, 3, 3.5, 3.7, 3.75),
xaxis = "x",
yaxis = "y",
carpet = "c",
aaxis = list(tickprefix = "a = ",
smoothing = 0,
minorgridcount = 9,
type = 'linear'),
baxis = list(tickprefix = "b = ",
smoothing = 0,
minorgridcount = 9,
type = 'linear')) %>%
layout(margin = list(t = 40, r = 30, b = 30, l = 30),
yaxis = list(range = c(0.388,4.361)),
xaxis = list(range = c(0.667,5.932)))
p
p <- plot_ly(width = 600, height = 600) %>%
add_trace(type = 'contourcarpet',
a = c(0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3),
b = c(4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6),
z = c(1, 1.96, 2.56, 3.0625, 4, 5.0625, 1, 7.5625, 9, 12.25, 15.21, 14.0625),
xaxis = "x",
yaxis = "y",
carpet = "c",
autocontour = F,
contours = list(start = 1, end = 14, size = 1),
line = list(width = 2, smoothing = 0),
colorbar = list(len = 0.4, y = 0.25)) %>%
add_trace(type = 'carpet',
a = c(0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3),
b = c(4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6),
x = c(2, 3, 4, 5, 2.2, 3.1, 4.1, 5.1, 1.5, 2.5, 3.5, 4.5),
y = c(1, 1.4, 1.6, 1.75, 2, 2.5, 2.7, 2.75, 3, 3.5, 3.7, 3.75),
xaxis = "x",
yaxis = "y",
carpet = "c",
aaxis = list(tickprefix = "a = ",
smoothing = 0,
minorgridcount = 9,
type = 'linear'),
baxis = list(tickprefix = "b = ",
smoothing = 0,
minorgridcount = 9,
type = 'linear')) %>%
layout(margin = list(t = 40, r = 30, b = 30, l = 30),
yaxis = list(range = c(0.388,4.361)),
xaxis = list(range = c(0.667,5.932)))
p
data <- fromJSON(file="https://raw.githubusercontent.com/bcdunbar/datasets/master/airfoil_data.json")
p <- plot_ly() %>%
add_trace(type = "carpet",
a = list(1.083, 1.214, 1.344, 1.475, 1.605, 1.736, 1.866, 1.997, 2.128, 2.258, 2.389,
2.519, 2.650, 2.780, 2.911, 3.041, 3.172, 3.303, 3.433, 3.564, 3.694, 3.825,
3.955, 4.086, 4.217, 4.347, 4.478, 4.608, 4.739, 4.869, 5.000),
b = list(0.000, 0.090, 0.180, 0.269, 0.359, 0.449, 0.539, 0.628, 0.718, 0.808, 0.898,
0.987, 1.077, 1.167, 1.257, 1.346, 1.436, 1.526, 1.616, 1.705, 1.795, 1.885,
1.975, 2.064, 2.154, 2.244, 2.334, 2.424, 2.513, 2.603, 2.693, 2.783, 2.872,
2.962, 3.052, 3.142, 3.231, 3.321, 3.411, 3.501, 3.590, 3.680, 3.770, 3.860,
3.949, 4.039, 4.129, 4.219, 4.308, 4.398, 4.488, 4.578, 4.668, 4.757, 4.847,
4.937, 5.027, 5.116, 5.206, 5.296, 5.386, 5.475, 5.565, 5.655, 5.745, 5.834,
5.924, 6.014, 6.104, 6.193, 6.283),
x = data[[1]]$x,
y = data[[1]]$y,
aaxis = list(startlinewidth = 2,
startline = TRUE,
showticklabels = "none",
endline = TRUE,
showgrid = FALSE,
endlinewidth = 2,
smoothing = 0),
baxis = list(startline = FALSE,
endline = FALSE,
showticklabels = "none",
smoothing = 0,
showgrid = FALSE)) %>%
add_trace(type = 'contourcarpet',
z = data[[2]]$z,
autocolorscale = FALSE,
zmax = 1,
name = "Pressure",
colorscale = "Viridis",
zmin = -8,
colorbar = list(y = 0,
yanchor = "bottom",
titleside = "right",
len = 0.75,
title = "Pressure coefficient, c<sub>p</sub>"),
contours = list(start = -1,
size = 0.025,
end = 1.000,
showlines = FALSE),
line = list(smoothing = 0),
autocontour = FALSE,
zauto = FALSE) %>%
add_trace(type = 'contourcarpet',
z = data[[3]]$z,
opacity = 0.300,
showlegend = TRUE,
name = "Streamlines",
autocontour = TRUE,
ncontours = 50,
contours = list(coloring = "none"),
line = list(color = "white", width = 1)) %>%
add_trace(type = 'contourcarpet',
z = data[[4]]$z,
showlegend = TRUE,
name = "Pressure<br>contours",
autocontour = FALSE,
line = list(color = "rgba(0, 0, 0, 0.5)", smoothing = 1),
contours = list(size = 0.250,
start = -4,
coloring = "none",
end = 1.000,
showlines = TRUE)) %>%
add_trace(type = 'scatter',
x = data[[5]]$x,
y = data[[5]]$y,
legendgroup = "g1",
name = "Surface<br>pressure",
mode = "lines",
hoverinfo = "skip",
line = list(color = "rgba(255, 0, 0, 0.5)",
width = 1,
shape = "spline",
smoothing = 1),
fill = "toself",
fillcolor = "rgba(255, 0, 0, 0.2)") %>%
add_trace(type = 'scatter',
x = data[[6]]$x,
y = data[[6]]$y,
showlegend = FALSE,
legendgroup = "g1",
mode = "lines",
hoverinfo = "skip",
line = list(color = "rgba(255, 0, 0, 0.3)", width = 1)) %>%
add_trace(type = 'scatter',
x = data[[7]]$x,
y = data[[7]]$y,
showlegend = FALSE,
legendgroup = "g1",
name = "cp",
mode = "lines",
line = list(color = "rgba(255, 0, 0, 0.2)", width = 0)) %>%
layout(xaxis = list(zeroline = FALSE,
scaleratio = 1,
scaleanchor = 'y',
range = c(-3.800,3.800),
showgrid = FALSE),
yaxis = list(zeroline = FALSE,
range = c(-1.800,1.800),
showgrid = FALSE),
title = "Flow over a Karman-Trefftz airfoil",
hovermode = "closest",
margin = list(r = 60, b = 40, l = 40, t = 80))
p
data <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/polar_dataset.csv")
p <- plot_ly(data,
type = 'scatterpolar',
mode = 'lines') %>%
add_trace(r = ~x1,
theta = ~y,
name = 'Figure8',
line = list(color = 'peru')) %>%
add_trace(r = ~x2,
theta = ~y,
name = 'Cardioid',
line = list(color = 'darkviolet')) %>%
add_trace(r = ~x3,
theta = ~y,
name = 'Hypercardioid',
line = list(color = 'deepskyblue')) %>%
add_trace(r = ~x4,
theta = ~y,
name = 'Subcardioid',
line = list(color = 'orangered')) %>%
add_trace(r = ~x5,
theta = ~y,
name = 'Supercardioid',
line = list(color = 'green')) %>%
layout(title = 'Mic Patterns',
font = list(family = 'Arial', size = 12, color = '#000'),
showlegend = F)
p
p <- plot_ly(type = 'scatterpolar',
mode = 'lines') %>%
add_trace(r = c(0, 1.5, 1.5, 0, 2.5, 2.5, 0),
theta = c(0, 10, 25, 0, 205, 215, 0),
fill = 'toself',
fillcolor = '#709Bff',
line = list(color = 'black')) %>%
add_trace(r = c(0, 3.5, 3.5, 0),
theta = c(0, 55, 75, 0),
fill = 'toself',
fillcolor = '#E4FF87',
line = list(color = 'black')) %>%
add_trace(r = c(0, 4.5, 4.5, 0, 4.5, 4.5, 0),
theta = c(0, 100, 120, 0, 305, 320, 0),
fill = 'toself',
fillcolor = '#FFAA70',
line = list(color = 'black')) %>%
add_trace(r = c(0, 4, 4, 0),
theta = c(0, 165, 195, 0),
fill = 'toself',
fillcolor = '#FFDF70',
line = list(color = 'black')) %>%
add_trace(r = c(0, 3, 3, 0),
theta = c(0, 262.5, 277.5, 0),
fill = 'toself',
fillcolor = '#B6FFB4',
line = list(color = 'black')) %>%
layout(polar = list(radialaxis = list(visible = T, range = c(0,5))),
showlegend = F)
p
p <- plot_ly(type = 'scatterpolar',
mode = 'lines') %>%
add_trace(r = c(5, 4, 2, 4, 5),
theta = c("a", "b", "c", "d", "a"),
name = 'angular categories',
fill = 'toself') %>%
add_trace(r = c("a", "b", "c", "d", "b", "f", "a"),
theta = c(1, 4, 2, 1.5, 1.5, 6, 5),
thetaunit = 'radians',
name = 'radial categories',
fill = 'toself',
subplot = 'polar2') %>%
add_trace(r = c(5, 4, 2, 4, 5),
theta = c("a", "b", "c", "d", "a"),
name = 'angular categories (w/ categoryarray)',
fill = 'toself',
subplot = 'polar3') %>%
add_trace(r = c("a", "b", "c", "d", "b", "f", "a", "a"),
theta = c(45, 90, 180, 200, 300, 15, 20, 45),
name = 'radial categories (w/ category descending)',
fill = 'toself',
subplot = 'polar4') %>%
layout(polar = list(domain = list(x = c(0,0.46),
y = c(0.56,1)),
radialaxis = list(angle = 45),
angularaxis = list(direction = 'clockwise', period = 6)),
polar2 = list(domain = list(x = c(0,0.46),
y = c(0,0.44)),
radialaxis = list(angle = 180,
tickangle = -180)),
polar3 = list(domain = list(x = c(0.54,1),
y = c(0.56,1)),
sector = c(150,400),
radialaxis = list(angle = -45),
angularaxis = list(categoryarray = c("d", "a", "c", "b"))),
polar4 = list(domain = list(x = c(0.54,1),
y = c(0,0.44)),
radialaxis = list(categoryorder = "category descending"),
angularaxis = list(thetaunit= "radians",
dtick = 0.3141592653589793)))
p
p <- plot_ly(type = 'scatterpolar',
mode = "lines+markers") %>%
add_trace(r = c(1,2,3,4,5),
theta = c(0,90,180,360,0),
line = list(color = "#ff66ab"),
marker = list(color = "#8090c7",
symbol = 'square',
size = 8),
text = "sector: 135->225<br>rotation: 90<br>direction: counterclockwise") %>%
add_trace(r = c(1,2,3,4,5),
theta = c(0,90,180,360,0),
line = list(color = "#ff66ab"),
marker = list(color = "#8090c7",
symbol = 'square',
size = 8),
text = "sector: 135->225<br>rotation: 90<br>direction: counterclockwise",
subplot = 'polar2') %>%
layout(polar = list(domain = list(x = c(0,0.4),
y = c(0,1)),
radialaxis = list(tickfont = list(size = 8)),
angularaxis = list(tickfont = list(size = 8),
rotation = 90,
direction = 'counterclockwise')),
polar2 = list(domain = list(x = c(0.6,1),
y = c(0,1)),
radialaxis = list(tickfont = list(size = 8)),
angularaxis = list(tickfont = list(size = 8),
rotation = 90,
direction = 'clockwise')),
showlegend = F)
p
p <- plot_ly(type = 'scatterpolar',
mode = "lines+markers") %>%
add_trace(r = c(1,2,3,4,5),
theta = c(0,90,180,360,0),
line = list(color = "#ff66ab"),
marker = list(color = "#8090c7",
symbol = 'square',
size = 8)) %>%
add_trace(r = c(1,2,3,4,5),
theta = c(0,90,180,360,0),
line = list(color = "#ff66ab"),
marker = list(color = "#8090c7",
symbol = 'square',
size = 8),
subplot = 'polar2') %>%
layout(polar = list(domain = list(x = c(0,0.4),
y = c(0,1)),
sector = c(150,210),
radialaxis = list(
tickfont = list(size = 8)),
angularaxis = list(tickfont = list(size = 8))),
polar2 = list(domain = list(x = c(0.6,1),
y = c(0,1)),
radialaxis = list(tickfont = list(size = 8)),
angularaxis = list(tickfont = list(size = 8))),
showlegend = F)
p
p <- plot_ly(type = 'scatterpolar',
mode = 'lines') %>%
add_trace(r = c(1,2,3),
theta = c(50,100,200),
marker = list(symbol = 'square')) %>%
add_trace(r = c(1,2,3),
theta = c(1,2,3),
thetaunit = 'radians') %>%
add_trace(r = c("a", "b", "c", "d"),
theta = c("D","C","B","A"),
subplot = 'polar2') %>%
add_trace(r = c(50,300,900),
theta = c(0,90,180),
subplot = 'polar3') %>%
add_trace(r = c(3,3,4,3),
theta = c(0,45,90,270),
fill = 'toself',
subplot = 'polar4') %>%
layout(polar = list(domain = list(x = c(0,0.46),
y = c(0.56,1)),
radialaxis = list(range = c(1,4)),
angularaxis = list(thetaunit = 'radians')),
polar2 = list(domain = list(x = c(0,0.46),
y = c(0,0.42))),
polar3 = list(domain = list(x = c(0.54,1),
y = c(0.56,1)),
sector = c(0,180),
radialaxis = list(type = 'log', angle = 45)),
polar4 = list(domain = list(x = c(0.54,1),
y = c(0,0.44)),
radialaxis = list(visible = F,
range = c(0,6))),
showlegend = F)
p
data <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/hobbs-pearson-trials.csv")
j = 1
k = 2
p <- plot_ly(type = 'scatterpolargl',
mode = 'markers')
for (i in 1:(length(data)/2)){
p <- p %>%
add_trace(r = data[,j],
theta = data[,k],
name = paste('Trial ', i),
marker = list(size = 15,
line = list(color = '#FFF'),
opacity = 0.7)) %>%
layout(title = "Hobbs-Pearson Trials",
showlegend = F,
paper_bgcolor = "rgb(223, 223, 223)",
polar = list(bgcolor = "rgb(223, 223, 223)",
angularaxis = list(tickwidth = 2,
linewidth = 3,
layer = 'below traces'),
radialaxis = list(side = 'counterclockwise',
showline = T,
linewidth = 2,
tickwidth = 2,
gridcolor = '#FFF',
gridwidth = 2)))
j <- j + 2
k <- k + 2
}
p
p <- plot_ly(type = 'scatterpolar',
fill = 'toself') %>%
add_trace(r = c(39, 28, 8, 7, 28, 39),
theta = c('A','B','C', 'D', 'E', 'A'),
name = 'Group A') %>%
add_trace(r = c(1.5, 10, 39, 31, 15, 1.5),
theta = c('A','B','C', 'D', 'E', 'A'),
name = 'Group B') %>%
layout(polar = list(radialaxis = list(visible = T,
range = c(0,50))))
p
Plotly R Graphing Library | R | Plotly. (2020). Retrieved August 5, 2020, from https://plotly.com/r/