Los ejemplos son tomados de la página oficial de plotly, principalmente se obtienen algunos ejemplos gráficos de plotly.
Librerías
Cómo ajustar las propiedades de los ejes en R. Siete ejemplos de ejes lineales y logarítmicos, títulos de ejes y estilo y colorear ejes y líneas de cuadrícula grid lines 2.
p <- plot_ly(x = ~seq(1, 4, by = 0.25),
y = ~seq(1, 4, by = 0.25),
marker = list(color = "#003760 ",size=10)) %>%
layout(xaxis = list(title="x",
autotick = FALSE,
ticks = "outside",
tick0 = 0,
dtick = 0.25,
ticklen = 5,
tickwidth = 2,
tickcolor = toRGB("blue")),
yaxis = list(title="y",
autotick = FALSE,
ticks = "outside",
tick0 = 0,
dtick = 0.25,
ticklen = 5,
tickwidth = 2,
tickcolor = toRGB("blue")))
pp <- plot_ly(x = ~seq(1e6, 1e7, length.out = 10),
y = ~seq(1e6, 1e7, length.out = 10)) %>%
add_markers() %>%
add_markers(y = ~rev(seq(1e6, 1e7, length.out = 10))) %>%
layout(xaxis = list(title = "AXIS TITLE",
titlefont = list(family = "Arial, sans-serif",
size = 18,
color = "lightgrey"),
showticklabels = TRUE,
tickangle = 45,
tickfont = list(family = "Old Standard TT, serif",
size = 14,
color = "black"),
exponentformat = "E"),
yaxis = list(title = "AXIS TITLE",
titlefont = list(family = "Arial, sans-serif",
size = 18,
color = "lightgrey"),
showticklabels = TRUE,
tickangle = 45,
tickfont = list(family = "Old Standard TT, serif",
size = 14,
color = "black"),
exponentformat = "E"),
showlegend = FALSE)
pp <- plot_ly(x = ~seq(-1, 4),
y = ~seq(-1, 4),
marker = list(color = "#AAABAC",
size = 20)) %>%
layout(xaxis = list(title = "x",
zeroline = TRUE,
showline = TRUE,
mirror = "ticks",
gridcolor = toRGB("gray50"),
gridwidth = 2,
zerolinecolor = toRGB("red"),
zerolinewidth = 4,
linecolor = toRGB("black"),
linewidth = 6),
yaxis = list(title = "y",
zeroline = TRUE,
showline = TRUE,
mirror = "ticks",
gridcolor = toRGB("gray50"),
gridwidth = 2,
zerolinecolor = toRGB("red"),
zerolinewidth = 4,
linecolor = toRGB("black"),
linewidth = 6))
pp <- plot_ly(x = c('A12', 'BC2', 109, '12F', 215, 304),
y = c(1,6,3,5,1,4),
type = 'bar',
name = 'Team A',
text = c('Apples', 'Pears', 'Peaches', 'Bananas', 'Pineapples', 'Cherries')) %>%
layout(title = 'Inventory',
xaxis = list(type = 'category',
title = 'Product Code'),
yaxis = list(title = '# of Items in Stock',
range = c(0,7)))
pp<- plot_ly(orientation='h',
line=list(color='gray'),
height=400, width=600) %>%
add_boxplot(x=c(2,3,1,5),
y=c('A','A','A','A'),
name='A') %>%
add_boxplot(x=c(8,3,6,5),
y=c('B','B','B','B'),
name='B') %>%
add_boxplot(x=c(2,3,2,5),
y=c('C','C','C','C'),
name='C') %>%
add_boxplot(x=c(7.5,3,6,4),
y=c('D','D','D','D'),
name='D') %>%
layout(title = '',
yaxis = list(title = "",
autorange = TRUE,
categoryorder = "category descending",
domain = c(0, 1),
range = c(-0.5, 3.5),
showline = TRUE,
type = "category"),
margin = list(r = 10,
t = 25,
b = 40,
l = 110),
legend = list(x = 0.986145833333,
y = 0.936263886049),
shapes = list(list(line = list(color = "rgba(68, 68, 68, 0.5)", width = 1),
type = "line",
x0 = -0.3,
x1 = 1.2,
xref = "paper",
y0 = 0.5,
y1 = 0.5,
yref = "paper"),
list(line = list(color = "rgba(68, 68, 68, 0.63)", width = 1),
type = "line",
x0 = -0.3,
x1 = 1.2,
xref = "paper",
y0 = 1,
y1 = 1,
yref = "paper")),
annotations = list(list(x = -0.0951769406393,
y = 1.06972670892,
showarrow = FALSE,
text = "Subgroup",
xref = "paper",
yref = "paper"),
list(x = -0.235516552511,
y = 1.07060587474,
showarrow = FALSE,
text = "Group",
xref = "paper",
yref = "paper"),
list(x = -0.235516552511,
y = 0.922906017856,
showarrow = FALSE,
text = "One",
xref = "paper",
yref = "paper"),
list(x = -0.235516552511,
y = 0.375,
showarrow = FALSE,
text = "Two",
xref = "paper",
yref = "paper")))
pp<- plot_ly(width = 800,
height = 500) %>%
add_trace(x = c(0,1,1,0,0,1,1,2,2,3,3,2,2,3),
y = c(0,0,1,1,3,3,2,2,3,3,1,1,0,0),
mode = 'lines') %>%
add_trace(x = c(0,1,2,3),
y = c(1,2,4,8),
yaxis = "y2",
mode = 'lines') %>%
add_trace(x = c(1,10,100,10,1),
y = c(0,1,2,3,4),
xaxis = "x2",
yaxis ="y3",
mode = 'lines') %>%
add_trace(x = c(1,100,30,80,1),
y = c(1,1.5,2,2.5,3),
xaxis = "x2",
yaxis = "y4",
mode = 'lines') %>%
layout(title = "fixed-ratio axes",
xaxis = list(title = "shared X axis",
nticks = 10,
domain = c(0, 0.45)),
yaxis = list(title = "1:1",
scaleanchor = "x",
domain = c(0, 0.45)),
yaxis2 = list(title = "1:5",
scaleanchor = "x",
scaleratio = 0.2,
domain = c(0.55,1)),
xaxis2 = list(title = "unconstrained log X",
type = "log",
domain = c(0.55, 1),
anchor = "y3"),
yaxis3 = list(title = "Scale matches ->",
domain = c(0, 0.45),
anchor = "x2"),
yaxis4 = list(title = "Scale matches <-",
scaleanchor = "y3",
domain = c(0.55, 1),
anchor = "x2"),
showlegend= FALSE)
pset.seed(123)
# Create Random Data
data <- diamonds[sample(1:nrow(diamonds), size = 1000),]
p <- plot_ly(data,
x = ~carat,
y = ~cut,
z = ~price,
type = 'scatter3d',
mode = 'markers',
marker = list(size = 3)) %>%
layout(title = "3D Scatter plot",
scene = list(xaxis = list(titlefont = list(family = "Arial, sans-serif", size = 18, color = "lightgrey"),
tickfont = list(family = "Old Standard TT, serif", size = 14, color = "#ff9999"),
showgrid = F),
yaxis = list(titlefont = list(family = "Arial, sans-serif", size = 18, color = "lightgrey"),
tickfont = list(family = "Old Standard TT, serif", size = 14, color = "#ff9999"),
showgrid = F),
zaxis = list(titlefont = list(family = "Arial, sans-serif", size = 18, color = "lightgrey"),
tickfont = list(family = "Old Standard TT, serif", size = 14, color = "#ff9999"),
showgrid = F),
camera = list(eye = list(x = -1.25, y = 1.25, z = 1.25))))
pp <- plot_ly(type = "scatter",
x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
y = c(28.8, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9),
mode = "markers+lines") %>%
layout(xaxis = list(ticktext = list("One", "Three", "Five", "Seven", "Nine", "Eleven"),
tickvals = list(1, 3, 5, 7, 9, 11),
tickmode = "array"))
pdf <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')%>%
as.data.frame()
p <- plot_ly(df,
type = "scatter",
x = ~Date,
y = ~AAPL.High,
name = 'AAPL High',
mode = "lines",
line = list(color = '#17BECF')) %>%
add_trace(type = "scatter",
x = ~Date,
y = ~AAPL.Low,
name = 'AAPL Low',
mode = "lines",
line = list(color = '#7F7F7F')) %>%
layout(title = "Time Series with Custom Date-Time Format",
xaxis = list(type = 'date',
tickformat = "%d %B (%a)<br>%Y"))
pdf <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
p <- plot_ly(data=df,
type = "scatter",
x = ~Date,
y = ~mavg,
mode = "lines") %>%
layout(xaxis = list(type='date',
tickformatstops = list(list(dtickrange = list(NULL, 1000), value = "%H:%M:%S.%L ms"),
list(dtickrange = list(1000, 60000), value = "%H:%M:%S s"),
list(dtickrange = list(60000, 3600000), value = "%H:%M m"),
list(dtickrange = list(3600000, 86400000), value = "%H:%M h"),
list(dtickrange = list(86400000, 604800000), value = "%e. %b d"),
list(dtickrange = list(604800000, "M1"), value = "%e. %b w"),
list(dtickrange = list("M1", "M12"), value = "%b '%y M"),
list(dtickrange = list("M12", NULL), value = "%Y Y"))))
pp <- plot_ly(x = ~rnorm(10),
y = ~rnorm(10),
mode = "markers") %>%
layout(xaxis = list(title = "x Axis",
titlefont = list(family = "Courier New, monospace",
size = 18,
color = "#7f7f7f")),
yaxis = list(title = "y Axis",
titlefont = list(family = "Courier New, monospace",
size = 18,
color = "#7f7f7f")))
pset.seed(123)
n <- 1000
theta <- runif(n, 0, 2*pi)
u <- runif(n, -1, 1)
p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta),
y = ~sqrt(1 - u^2) * sin(theta),
z = ~u,
marker = list(size=5)) %>%
layout(title = "Layout options in a 3d scatter plot",
scene = list(xaxis = list(title = "Cos"),
yaxis = list(title = "Sin"),
zaxis = list(title = "Z")))
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
name = 'Tree 1') %>%
add_trace(y = ~Tree2,
name = 'Tree 2') %>%
add_trace(y = ~Tree3,
name = 'Tree 3',
showlegend = FALSE) %>%
add_trace(y = ~Tree4,
name = 'Tree 4') %>%
add_trace(y = ~Tree5,
name = 'Tree 5')
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines') %>%
add_trace(y = ~Tree2) %>%
add_trace(y = ~Tree3) %>%
add_trace(y = ~Tree4) %>%
add_trace(y = ~Tree5) %>%
layout(showlegend = FALSE)
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
name = 'Tree 1') %>%
add_trace(y = ~Tree2,
name = 'Tree 2')%>%
add_trace(y = ~Tree3,
name = 'Tree 3',
showlegend = FALSE) %>%
add_trace(y = ~Tree4,
name = 'Tree 4') %>%
add_trace(y = ~Tree5,
name = 'Tree 5')
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
name = 'Tree 1') %>%
add_trace(y = ~Tree2,
name = 'Tree 2') %>%
add_trace(y = ~Tree3,
name = 'Tree 3') %>%
add_trace(y = ~Tree4,
name = 'Tree 4') %>%
add_trace(y = ~Tree5,
name = 'Tree 5') %>%
layout(legend = list(x = 0.1, y = 0.9))
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
name = 'Tree 1') %>%
add_trace(y = ~Tree2,
name = 'Tree 2') %>%
add_trace(y = ~Tree3,
name = 'Tree 3') %>%
add_trace(y = ~Tree4,
name = 'Tree 4') %>%
add_trace(y = ~Tree5,
name = 'Tree 5') %>%
layout(legend = list(orientation = 'h'))
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
name = 'Tree 1') %>%
add_trace(y = ~Tree2,
name = 'Tree 2') %>%
add_trace(y = ~Tree3,
name = 'Tree 3') %>%
add_trace(y = ~Tree4,
name = 'Tree 4') %>%
add_trace(y = ~Tree5,
name = 'Tree 5') %>%
layout(legend = list(x = 100, y = 0.5))
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
name = 'Tree 1') %>%
add_trace(y = ~Tree2,
name = 'Tree 2') %>%
add_trace(y = ~Tree3,
name = 'Tree 3') %>%
add_trace(y = ~Tree4,
name = 'Tree 4') %>%
add_trace(y = ~Tree5,
name = 'Tree 5') %>%
layout(legend = list(x = 100, y = 0.5))
pdata <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
name = 'Tree 1') %>%
add_trace(y = ~Tree2,
name = 'Tree 2') %>%
add_trace(y = ~Tree3,
name = 'Tree 3') %>%
add_trace(y = ~Tree4,
name = 'Tree 4') %>%
add_trace(y = ~Tree5,
name = 'Tree 5') %>%
layout(legend = list(font = list(family = "sans-serif", size = 12, color = "#000"),
bgcolor = "#E2E2E2",
bordercolor = "#FFFFFF",
borderwidth = 2))
pLa legendgroup agrupa las entradas de la leyenda de modo que al hacer clic en una entrada de leyenda se ocultarán o mostrarán todas las tramas de ese grupo.
data <- spread(Orange, Tree, circumference) %>%
rename(c("1" = "Tree1", "2" = "Tree2", "3" = "Tree3", "4" = "Tree4", "5" = "Tree5"))
p <- plot_ly(data,
x = ~age,
y = ~Tree1,
type = 'scatter',
mode = 'lines',
legendgroup = 'group1',
name = 'Zone 1 - Tree 1') %>%
add_trace(y = ~Tree2,
legendgroup = 'group2',
name = 'Zone 2 - Tree 1') %>%
add_trace(y = ~Tree3,
legendgroup = 'group1',
name = 'Zone 1 - Tree 2') %>%
add_trace(y = ~Tree4,
legendgroup = 'group2',
name = 'Zone 2 - Tree 2') %>%
add_trace(y = ~Tree5,
legendgroup = 'group1',
name = 'Zone 1 - Tree 3')
pdf <- data.frame(x = c("a","b","c"), y = c(2,3,2), y2 = c(4,2,4))
p1 <- df %>%
plot_ly(type = 'bar',
x = ~x,
y = ~y,
color = ~x,
legendgroup = ~x) %>%
layout(xaxis = list(showgrid = F),
yaxis = list(showgrid = F))
p2 <- df %>%
plot_ly(type = 'bar',
x = ~x,
y = ~y2,
color = ~x,
legendgroup = ~x,
showlegend = F) %>%
layout(xaxis = list(showgrid = F),
yaxis = list(showgrid = F))
p <- subplot(p1, p2, nrows = 2, shareX = T)
px <- seq(-1, 3, length=50)
ones <- rep(1, 50)
a_list <- seq(1, 3, length=7)
b_list <- seq(2, 14, length=7)
df <- data.frame(cbind(x, (outer((x*x), a_list) + outer(ones, b_list))))
p <- plot_ly(df,
x = ~x,
y = ~V2,
type = 'scatter',
mode = 'lines') %>%
add_trace(y = ~V3) %>%
add_trace(y = ~V4) %>%
add_trace(y = ~V5) %>%
add_trace(y = ~V6) %>%
add_trace(y = ~V7) %>%
add_trace(y = ~V8) %>%
layout(colorway = c('#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844'))
pPara que los marcadores sean distintos, puede agregar un borde a los marcadores. Esto se puede lograr agregando marker:{..., line: {...}}
data <- data.frame(x = runif(500, min=3, max=6),
y = runif(500, min=3, max=6))
p <- plot_ly(data,
type = 'scatter',
mode = 'markers') %>%
add_trace(x = ~x,
y = ~y,
marker = list(color = 'rgb(231, 30, 145)',
size = 20,
line = list(color = 'rgb(147, 11, 89)', width = 2)),
showlegend = F) %>%
add_trace(x = c(2),
y = c(4.5),
marker = list(color = 'rgb(231, 30, 145)',
size = 120,
line = list(color = 'rgb(147, 11, 89)', width = 12)),
showlegend = F)
pFully opaque, es útil para marcadores que no se superponen. Cuando muchos puntos se superponen, puede resultar difícil observar la densidad.
data <- data.frame(x = runif(500, min=3, max=6),
y = runif(500, min=3, max=6))
p <- plot_ly(data,
type = 'scatter',
mode = 'markers') %>%
add_trace(x = ~x,
y = ~y,
marker = list(color = 'rgb(231, 30, 145)',
size = 20,
line = list(color = 'rgb(147, 11, 89)', width = 2)),
showlegend = F) %>%
add_trace(x = c(2,2),
y = c(4.25,4.75),
marker = list(color = 'rgb(231, 30, 145)',
size = 120,
line = list(color = 'rgb(147, 11, 89)', width = 12)),
showlegend = F)
pdata <- data.frame(x = runif(500, min=3, max=6),
y = runif(500, min=3, max=4.5),
x2 = runif(500, min=3, max=6),
y2 = runif(500, min=4.5, max=6))
p <- plot_ly(data,
type = 'scatter',
mode = 'markers') %>%
add_trace(x = ~x,
y = ~y,
opacity = 0.5,
marker = list(color = 'rgb(231, 30, 145)',
size = 20,
line = list(color = 'rgb(147, 11, 89)', width = 2)),
name = 'Opacity 0.5') %>%
add_trace(x = ~x2,
y = ~y2,
marker = list(color = 'rgb(231, 30, 145)',
size = 20,
line = list(color = 'rgb(147, 11, 89)', width = 2)),
name = 'Opacity 1.0') %>%
add_trace(x = c(2,2),
y = c(4.25,4.75),
opacity = 0.5,
marker = list(color = 'rgb(231, 30, 145)', size = 120,
line = list(color = 'rgb(147, 11, 89)', width = 12)),
showlegend = F)
pdata <- data.frame(x = runif(500, min=3, max=6),
y = runif(500, min=3, max=6))
p <- plot_ly(data,
type = 'scatter',
mode = 'markers') %>%
add_trace(x = ~x,
y = ~y,
marker = list(color = 'rgb(231, 30, 145)',
size = 20,
opacity = 0.5,
line = list(color = 'rgb(147, 11, 89)', width = 2)),
showlegend = F) %>%
add_trace(x = c(2,2),
y = c(4.25,4.75),
marker = list(color = 'rgb(231, 30, 145)',
size = 120,
opacity = 0.5,
line = list(color = 'rgb(147, 11, 89)', width = 12)),
showlegend = F)
pdata <- data.frame(x = runif(500, min=3, max=6),
y = runif(500, min=3, max=6))
p <- plot_ly(data,
type = 'scatter',
mode = 'markers') %>%
add_trace(x = ~x,
y = ~y,
marker = list(color = 'rgba(231, 30, 145,0.5)',
size = 20,
line = list(color = 'rgb(147, 11, 89)', width = 2)),
showlegend = F) %>%
add_trace(x = c(2,2),
y = c(4.25,4.75),
marker = list(color = 'rgba(231, 30, 145,0.5)',
size = 120,
line = list(color = 'rgb(147, 11, 89)', width = 12)),
showlegend = F)
ps<- seq.int(0, 15)
# initiate a line shape object
line <- list(
type = "line",
line = list(color = "pink"),
xref = "x",
yref = "y"
)
lines <- list()
for (i in c(0, 3, 5, 7, 9, 13)) {
line[["x0"]] <- i
line[["x1"]] <- i + 2
line[c("y0", "y1")] <- sin(i + 1)
lines <- c(lines, list(line))
}
p <- plot_ly(x = ~s,
y = ~sin(s),
mode = "lines") %>%
layout(title = 'Highlighting with Lines',
shapes = lines)
pdata("economics")
p <- plot_ly(economics,
x = ~date,
y = ~uempmed,
name = "unemployment") %>%
layout(title = 'Highlighting with Rectangles',
shapes = list(list(type = "rect", # add shapes to the layout
fillcolor = "blue",
line = list(color = "blue"),
opacity = 0.3,
x0 = "1980-01-01",
x1 = "1985-01-01",
xref = "x",
y0 = 4,
y1 = 12.5,
yref = "y"),
list(type = "rect",
fillcolor = "blue",
line = list(color = "blue"),
opacity = 0.2,
x0 = "2000-01-01",
x1 = "2005-01-01",
xref = "x",
y0 = 4,
y1 = 12.5,
yref = "y")))
pEl círculo esta centrado en \(\left(\frac{(x_{0}+x_{1})}{2}, \frac{(y_{0}+y_{1})}{2})\right)\).
df <- diamonds[sample(nrow(diamonds), 1000), ]
p <- plot_ly(df,
x = ~carat,
y = ~price,
color = ~carat,
size = ~carat,
text = ~paste("Clarity: ", clarity),
mode = "markers") %>%
layout(title = 'Highlighting Regions with Circles',
shapes = list(list(type = 'circle',
xref = 'x', x0 = .2, x1 = .7,
yref = 'y', y0 = 20, y1 = 3000,
fillcolor = 'rgb(50, 20, 90)',
line = list(color = 'rgb(50, 20, 90)'), opacity = 0.2),
list(type = 'circle',
xref = 'x', x0 = .75, x1 = 1.5,
yref = 'y', y0 = 2500, y1 = 7500,
fillcolor = 'rgb(30, 100, 120)',
line = list(color = 'rgb(30, 100, 120)'), opacity = 0.2),
list(type = 'circle',
xref = 'x', x0 = 1.6, x1 = 2.5,
yref = 'y', y0 = 12500, y1 = 18500,
fillcolor = 'rgb(90, 200, 75)',
line = list(color = 'rgb(90, 200, 75)'), opacity = 0.2)))
pSe pueden crear formas de diseño mediante código, pero también puede dibujar formas manualmente configurando el modo de arrastre en uno de los modos de dibujo de formas: trazo, trazo abierto, trazo cerrado, trazo circular o trazo recto. Si necesita cambiar entre diferentes dibujos de formas u otros modos de arrastre (panning, selecting, etc., etc.), se pueden agregar botones de la barra de modo en la configuración de su figura para seleccionar el modo de arrastre.
df <- diamonds[sample(nrow(diamonds), 1000), ]
p <- plot_ly(df,
x = ~carat,
y = ~price,
color = ~carat,
size = ~carat,
text = ~paste("Clarity: ", clarity),
mode = "markers") %>%
layout(dragmode="drawrect",
xaxis = list(title = 'Click and drag inside the figure to draw a rectangle or select another shape in the modebar'))
#config(p,modeBarButtonsToAdd = list("drawine","drawopenpath","drawclosedpath", "drawcircle", "drawrect", "eraseshape"))
pp <- plot_ly(x = c('Apples', 'Oranges', 'Watermelon', 'Pears'),
y = c(3, 1, 2, 4),
marker = list(color = 'rgba(231, 30, 145,1)'),
width = 500,
height = 500,
type = 'bar') %>%
layout(autosize = F,
yaxis = list(title = 'Y-axis Title',
ticktext = list('long label','Very long label','3','label'),
tickvals = list(1, 2, 3, 4),
tickmode = "array",
automargin = TRUE,
titlefont = list(size=30)))
pSupported File Formats
Con el paquete plotly en R, puede exportar los gráficos que creas como imágenes estáticas en los formatos .png, .jpg / .jpeg, .eps, .svg y / o .pdf usando Orca, una herramienta de línea de comandos de código abierto para generar imágenes estáticas.
if (!require("processx")) install.packages("processx")
p <- plot_ly(z = ~volcano) %>% add_surface()
orca(p, "surface-plot.svg")La función plotly_IMAGE() exporta sus gráficos en R como imágenes estáticas utilizando el servicio web Chart Studio. La imagen se almacenará en un archivo en el directorio de trabajo de su sesión de R.
Plotly R Graphing Library | R | Plotly. (2020). Retrieved October 21, 2020, from https://plotly.com/r/