Subplots with a line passing through them
up vote
1
down vote
favorite
I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
subplot(p1,p2, shareY = T)
and it gave me this plot

But what I'd love to see is a common line passing through 1.8 cutting all plots

also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
thank you
r r-plotly
add a comment |
up vote
1
down vote
favorite
I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
subplot(p1,p2, shareY = T)
and it gave me this plot

But what I'd love to see is a common line passing through 1.8 cutting all plots

also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
thank you
r r-plotly
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
subplot(p1,p2, shareY = T)
and it gave me this plot

But what I'd love to see is a common line passing through 1.8 cutting all plots

also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
thank you
r r-plotly
I need to pass a through a bunch of violin plots in plotly. So I have come up with this code.
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp
= rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin', box =
list(visible =T), meanline = list(visible = T))%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
subplot(p1,p2, shareY = T)
and it gave me this plot

But what I'd love to see is a common line passing through 1.8 cutting all plots

also the 'trace 0' to be replaced with 'cd' and 'trace 1' to be replaced with 'ad'
thank you
r r-plotly
r r-plotly
asked Nov 11 at 6:29
Ayesha Perera
275
275
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:
library(reshape2)
library(dplyr)
library(plotly)
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(cd$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(ad$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
vline <- function(x = 0, color = "red") {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color)
)
}
subplot(p1,p2, shareY = T)
Thanks, It does give the output, but is there a way to make that line continous?
– Ayesha Perera
Nov 11 at 7:10
Not as far as I know..
– CIAndrews
Nov 11 at 7:15
Okay, thank you
– Ayesha Perera
Nov 11 at 7:32
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:
library(reshape2)
library(dplyr)
library(plotly)
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(cd$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(ad$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
vline <- function(x = 0, color = "red") {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color)
)
}
subplot(p1,p2, shareY = T)
Thanks, It does give the output, but is there a way to make that line continous?
– Ayesha Perera
Nov 11 at 7:10
Not as far as I know..
– CIAndrews
Nov 11 at 7:15
Okay, thank you
– Ayesha Perera
Nov 11 at 7:32
add a comment |
up vote
1
down vote
accepted
You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:
library(reshape2)
library(dplyr)
library(plotly)
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(cd$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(ad$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
vline <- function(x = 0, color = "red") {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color)
)
}
subplot(p1,p2, shareY = T)
Thanks, It does give the output, but is there a way to make that line continous?
– Ayesha Perera
Nov 11 at 7:10
Not as far as I know..
– CIAndrews
Nov 11 at 7:15
Okay, thank you
– Ayesha Perera
Nov 11 at 7:32
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:
library(reshape2)
library(dplyr)
library(plotly)
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(cd$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(ad$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
vline <- function(x = 0, color = "red") {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color)
)
}
subplot(p1,p2, shareY = T)
You can use add_lines in each plot to add a horizontal line, and by setting name = 'cd' or 'ad' you label the legends:
library(reshape2)
library(dplyr)
library(plotly)
cd = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp = rexp(100,1))
cd = melt(cd, id= "id")
p1 = plot_ly(cd, x=~variable, y=~value, type = 'violin',name = 'cd', box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(cd$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=10, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
ad = data.frame(id = 1:100, norm = rnorm(100), poi = rpois(100, 1), exp =
rexp(100,1))
ad = melt(ad, id= "id")
p2 = plot_ly(ad, x=~variable, y=~value, type = 'violin',name = 'ad',box =
list(visible =T), meanline = list(visible = T))%>% add_lines(x = ~variable, y =
rep(1.8,length(ad$id)),showlegend=FALSE)%>%
layout(annotations = list(text = sprintf("Seeds=20, Coupons=5", 1:10),
font = list(size=16), xanchor = "center", xref = "paper", yref =
"paper", yanchor = "top", showarrow = F, y =1, x=0.5))
vline <- function(x = 0, color = "red") {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color)
)
}
subplot(p1,p2, shareY = T)
answered Nov 11 at 6:59
CIAndrews
1886
1886
Thanks, It does give the output, but is there a way to make that line continous?
– Ayesha Perera
Nov 11 at 7:10
Not as far as I know..
– CIAndrews
Nov 11 at 7:15
Okay, thank you
– Ayesha Perera
Nov 11 at 7:32
add a comment |
Thanks, It does give the output, but is there a way to make that line continous?
– Ayesha Perera
Nov 11 at 7:10
Not as far as I know..
– CIAndrews
Nov 11 at 7:15
Okay, thank you
– Ayesha Perera
Nov 11 at 7:32
Thanks, It does give the output, but is there a way to make that line continous?
– Ayesha Perera
Nov 11 at 7:10
Thanks, It does give the output, but is there a way to make that line continous?
– Ayesha Perera
Nov 11 at 7:10
Not as far as I know..
– CIAndrews
Nov 11 at 7:15
Not as far as I know..
– CIAndrews
Nov 11 at 7:15
Okay, thank you
– Ayesha Perera
Nov 11 at 7:32
Okay, thank you
– Ayesha Perera
Nov 11 at 7:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246393%2fsubplots-with-a-line-passing-through-them%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown