Multiple plots in the same axis in plotly
I'm trying to draw plots using the plotly where all of them share the same axis.
This is one dataset
X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790
and this is its plotly graph
plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)',
line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
and this is the other dataset
X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009
and this is its plot
plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)',
line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
I want these two graphs to share the same axis leaving the colours as it is.
r plotly r-plotly
add a comment |
I'm trying to draw plots using the plotly where all of them share the same axis.
This is one dataset
X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790
and this is its plotly graph
plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)',
line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
and this is the other dataset
X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009
and this is its plot
plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)',
line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
I want these two graphs to share the same axis leaving the colours as it is.
r plotly r-plotly
add a comment |
I'm trying to draw plots using the plotly where all of them share the same axis.
This is one dataset
X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790
and this is its plotly graph
plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)',
line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
and this is the other dataset
X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009
and this is its plot
plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)',
line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
I want these two graphs to share the same axis leaving the colours as it is.
r plotly r-plotly
I'm trying to draw plots using the plotly where all of them share the same axis.
This is one dataset
X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790
and this is its plotly graph
plot_ly(rr1, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(255,182,193,0.9)',
line=list(color='rgba(152,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
and this is the other dataset
X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009
and this is its plot
plot_ly(rr2, x=~variable, y=~value, type = 'scatter', marker=list(size=10, color='rgba(38,182,193,0.9)',
line=list(color='rgba(75,0,0,0.8)', width = 2)), name = "Character and Degree")%>%
layout(title = "Graph", font = list(family = "Arial Black"),yaxis=list(zerolinecolor = toRGB("red"),
gridcolor = "rgb(190,190,190)"), xaxis=list(gridcolor = "rgb(190,190,190)")) %>%
layout(plot_bgcolor='rgb(230, 230, 230)',paper_bgcolor='rgb(220, 220, 220)',
font = list(color = 'rgb(100,100,100)'))
I want these two graphs to share the same axis leaving the colours as it is.
r plotly r-plotly
r plotly r-plotly
edited Nov 23 '18 at 7:32
Stéphane Laurent
12.5k65392
12.5k65392
asked Nov 23 '18 at 5:50
Ayesha Perera
276
276
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can merge the two dataframes and use two add_markers
, one for each value column:
df1 <- read.table(text="X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790", header=TRUE)
df2 <- read.table(text=" X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009", header=TRUE)
df12 <- merge(df1, df2, by=c("X","variable"))
library(plotly)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter') %>%
add_markers(y=~value.y, type = 'scatter')
But the y-axis title and the legends are not nice:
So, modify them:
ax <- list(
title = "Value",
titlefont = list(
family = "Arial, sans-serif",
size = 18,
color = "Red"
),
showticklabels = TRUE
)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter', name="value1") %>%
add_markers(y=~value.y, type = 'scatter', name="value2") %>%
layout(yaxis=ax)
Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
– Ayesha Perera
Nov 23 '18 at 7:46
@AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
– Stéphane Laurent
Nov 23 '18 at 7:52
Here for the shapes.
– Stéphane Laurent
Nov 23 '18 at 7:54
@ Stéphane Laurent Thank you very much for the complete answer
– Ayesha Perera
Nov 23 '18 at 7:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53441252%2fmultiple-plots-in-the-same-axis-in-plotly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can merge the two dataframes and use two add_markers
, one for each value column:
df1 <- read.table(text="X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790", header=TRUE)
df2 <- read.table(text=" X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009", header=TRUE)
df12 <- merge(df1, df2, by=c("X","variable"))
library(plotly)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter') %>%
add_markers(y=~value.y, type = 'scatter')
But the y-axis title and the legends are not nice:
So, modify them:
ax <- list(
title = "Value",
titlefont = list(
family = "Arial, sans-serif",
size = 18,
color = "Red"
),
showticklabels = TRUE
)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter', name="value1") %>%
add_markers(y=~value.y, type = 'scatter', name="value2") %>%
layout(yaxis=ax)
Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
– Ayesha Perera
Nov 23 '18 at 7:46
@AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
– Stéphane Laurent
Nov 23 '18 at 7:52
Here for the shapes.
– Stéphane Laurent
Nov 23 '18 at 7:54
@ Stéphane Laurent Thank you very much for the complete answer
– Ayesha Perera
Nov 23 '18 at 7:58
add a comment |
You can merge the two dataframes and use two add_markers
, one for each value column:
df1 <- read.table(text="X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790", header=TRUE)
df2 <- read.table(text=" X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009", header=TRUE)
df12 <- merge(df1, df2, by=c("X","variable"))
library(plotly)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter') %>%
add_markers(y=~value.y, type = 'scatter')
But the y-axis title and the legends are not nice:
So, modify them:
ax <- list(
title = "Value",
titlefont = list(
family = "Arial, sans-serif",
size = 18,
color = "Red"
),
showticklabels = TRUE
)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter', name="value1") %>%
add_markers(y=~value.y, type = 'scatter', name="value2") %>%
layout(yaxis=ax)
Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
– Ayesha Perera
Nov 23 '18 at 7:46
@AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
– Stéphane Laurent
Nov 23 '18 at 7:52
Here for the shapes.
– Stéphane Laurent
Nov 23 '18 at 7:54
@ Stéphane Laurent Thank you very much for the complete answer
– Ayesha Perera
Nov 23 '18 at 7:58
add a comment |
You can merge the two dataframes and use two add_markers
, one for each value column:
df1 <- read.table(text="X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790", header=TRUE)
df2 <- read.table(text=" X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009", header=TRUE)
df12 <- merge(df1, df2, by=c("X","variable"))
library(plotly)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter') %>%
add_markers(y=~value.y, type = 'scatter')
But the y-axis title and the legends are not nice:
So, modify them:
ax <- list(
title = "Value",
titlefont = list(
family = "Arial, sans-serif",
size = 18,
color = "Red"
),
showticklabels = TRUE
)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter', name="value1") %>%
add_markers(y=~value.y, type = 'scatter', name="value2") %>%
layout(yaxis=ax)
You can merge the two dataframes and use two add_markers
, one for each value column:
df1 <- read.table(text="X variable value
1 1 SH 0.002814895
2 1 VH 0.002591173
3 1 SS 0.002599700
4 1 HCG 0.002810790", header=TRUE)
df2 <- read.table(text=" X variable value
1 1 SH 0.000982607
2 1 VH 0.000917569
3 1 SS 0.000911039
4 1 HCG 0.000971009", header=TRUE)
df12 <- merge(df1, df2, by=c("X","variable"))
library(plotly)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter') %>%
add_markers(y=~value.y, type = 'scatter')
But the y-axis title and the legends are not nice:
So, modify them:
ax <- list(
title = "Value",
titlefont = list(
family = "Arial, sans-serif",
size = 18,
color = "Red"
),
showticklabels = TRUE
)
plot_ly(df12, x=~variable) %>%
add_markers(y=~value.x, type = 'scatter', name="value1") %>%
add_markers(y=~value.y, type = 'scatter', name="value2") %>%
layout(yaxis=ax)
answered Nov 23 '18 at 7:23
Stéphane Laurent
12.5k65392
12.5k65392
Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
– Ayesha Perera
Nov 23 '18 at 7:46
@AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
– Stéphane Laurent
Nov 23 '18 at 7:52
Here for the shapes.
– Stéphane Laurent
Nov 23 '18 at 7:54
@ Stéphane Laurent Thank you very much for the complete answer
– Ayesha Perera
Nov 23 '18 at 7:58
add a comment |
Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
– Ayesha Perera
Nov 23 '18 at 7:46
@AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
– Stéphane Laurent
Nov 23 '18 at 7:52
Here for the shapes.
– Stéphane Laurent
Nov 23 '18 at 7:54
@ Stéphane Laurent Thank you very much for the complete answer
– Ayesha Perera
Nov 23 '18 at 7:58
Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
– Ayesha Perera
Nov 23 '18 at 7:46
Thank you. Is there a way to change the shape and the color of the dots and add lines around the dot
– Ayesha Perera
Nov 23 '18 at 7:46
@AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
– Stéphane Laurent
Nov 23 '18 at 7:52
@AyeshaPerera You're welcome. Look at here for the borders around the dots and the color. I have not found for the shape yet.
– Stéphane Laurent
Nov 23 '18 at 7:52
Here for the shapes.
– Stéphane Laurent
Nov 23 '18 at 7:54
Here for the shapes.
– Stéphane Laurent
Nov 23 '18 at 7:54
@ Stéphane Laurent Thank you very much for the complete answer
– Ayesha Perera
Nov 23 '18 at 7:58
@ Stéphane Laurent Thank you very much for the complete answer
– Ayesha Perera
Nov 23 '18 at 7:58
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%2f53441252%2fmultiple-plots-in-the-same-axis-in-plotly%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