Loop around dataframe columns and make a plotly of the columns that are present?2019 Community Moderator ElectionHow to sort a dataframe by multiple column(s)?R Shiny Plotly 3D : Change the title of x , y , z axis to actual variable name and add legend titleGenerate flexdashboard in RmarkdownPlotly, add border around points created with add_markersSharing R presentation with plotly iframesPlotly R chart from two different dataframeMake a line chart with plotly for multiple columnOrdering columns in Plotly horizontal bar chartHow to make plotly “scatter3d” respect order of factor levels in RHow to loop around table columns to get plotly traces?
is 'sed' thread safe
Why do phishing e-mails use faked e-mail addresses instead of the real one?
Is there a math equivalent to the conditional ternary operator?
Can an earth elemental drown/bury its opponent underground using earth glide?
What is better: yes / no radio, or simple checkbox?
Can a Trickery Domain cleric cast a spell through the Invoke Duplicity clone while inside a Forcecage?
In which way proportional valves are controlled solely by current?
PTIJ: Aharon, King of Egypt
Can we carry rice to Japan?
When do _WA_Sys_ statistics Get Updated?
Caulking a corner instead of taping with joint compound?
Ahoy, Ye Traveler!
Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?
Is divide-by-zero a security vulnerability?
How do you say “my friend is throwing a party, do you wanna come?” in german
What is a term for a function that when called repeatedly, has the same effect as calling once?
Why are special aircraft used for the carriers in the United States Navy?
How to get the first element while continue streaming?
Practical reasons to have both a large police force and bounty hunting network?
Should we avoid writing fiction about historical events without extensive research?
Split a number into equal parts given the number of parts
Why would the IRS ask for birth certificates or even audit a small tax return?
I can't die. Who am I?
How to mitigate "bandwagon attacking" from players?
Loop around dataframe columns and make a plotly of the columns that are present?
2019 Community Moderator ElectionHow to sort a dataframe by multiple column(s)?R Shiny Plotly 3D : Change the title of x , y , z axis to actual variable name and add legend titleGenerate flexdashboard in RmarkdownPlotly, add border around points created with add_markersSharing R presentation with plotly iframesPlotly R chart from two different dataframeMake a line chart with plotly for multiple columnOrdering columns in Plotly horizontal bar chartHow to make plotly “scatter3d” respect order of factor levels in RHow to loop around table columns to get plotly traces?
I have a peice of code that produces a plotly graph but the issue is that each time I run this code not all the columns are necessarily there. At the minute I am just running the code till I get an error and then commenting out the add_trace part that is missing but this is getting tedious.
How can I set it up to look at the df and add the traces for only the columns that currently exist.
graph <- plot_ly(Data, x = ~Weeknumber, y = ~Student, name = 'Student', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = red, hoverinfo = 'text',
text = ~paste('Date:', WeekStart)) %>%
add_trace(y = ~Senior, name = 'Senior', fillcolor = green) %>%
add_trace(y = ~Child, name = 'Child', fillcolor = blue) %>%
add_trace(y = ~Adult, name = 'Adult', fillcolor = purple) %>%
layout(title = 'Revenue',
xaxis = list(title = "Date",
showgrid = FALSE),
yaxis = list(title = "Revenue",
showgrid = FALSE))
r r-plotly
add a comment |
I have a peice of code that produces a plotly graph but the issue is that each time I run this code not all the columns are necessarily there. At the minute I am just running the code till I get an error and then commenting out the add_trace part that is missing but this is getting tedious.
How can I set it up to look at the df and add the traces for only the columns that currently exist.
graph <- plot_ly(Data, x = ~Weeknumber, y = ~Student, name = 'Student', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = red, hoverinfo = 'text',
text = ~paste('Date:', WeekStart)) %>%
add_trace(y = ~Senior, name = 'Senior', fillcolor = green) %>%
add_trace(y = ~Child, name = 'Child', fillcolor = blue) %>%
add_trace(y = ~Adult, name = 'Adult', fillcolor = purple) %>%
layout(title = 'Revenue',
xaxis = list(title = "Date",
showgrid = FALSE),
yaxis = list(title = "Revenue",
showgrid = FALSE))
r r-plotly
add a comment |
I have a peice of code that produces a plotly graph but the issue is that each time I run this code not all the columns are necessarily there. At the minute I am just running the code till I get an error and then commenting out the add_trace part that is missing but this is getting tedious.
How can I set it up to look at the df and add the traces for only the columns that currently exist.
graph <- plot_ly(Data, x = ~Weeknumber, y = ~Student, name = 'Student', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = red, hoverinfo = 'text',
text = ~paste('Date:', WeekStart)) %>%
add_trace(y = ~Senior, name = 'Senior', fillcolor = green) %>%
add_trace(y = ~Child, name = 'Child', fillcolor = blue) %>%
add_trace(y = ~Adult, name = 'Adult', fillcolor = purple) %>%
layout(title = 'Revenue',
xaxis = list(title = "Date",
showgrid = FALSE),
yaxis = list(title = "Revenue",
showgrid = FALSE))
r r-plotly
I have a peice of code that produces a plotly graph but the issue is that each time I run this code not all the columns are necessarily there. At the minute I am just running the code till I get an error and then commenting out the add_trace part that is missing but this is getting tedious.
How can I set it up to look at the df and add the traces for only the columns that currently exist.
graph <- plot_ly(Data, x = ~Weeknumber, y = ~Student, name = 'Student', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = red, hoverinfo = 'text',
text = ~paste('Date:', WeekStart)) %>%
add_trace(y = ~Senior, name = 'Senior', fillcolor = green) %>%
add_trace(y = ~Child, name = 'Child', fillcolor = blue) %>%
add_trace(y = ~Adult, name = 'Adult', fillcolor = purple) %>%
layout(title = 'Revenue',
xaxis = list(title = "Date",
showgrid = FALSE),
yaxis = list(title = "Revenue",
showgrid = FALSE))
r r-plotly
r r-plotly
asked 15 hours ago
JoshJosh
193
193
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Reshape your Data
to a long vector :
Data <- Data %>% tidyr::gather(key="variable",value="value",-Weeknumber,-WeekStart)
Then call plot_ly and distribute color with the variable
column:
plot_ly(Data,x=~Weeknumber, y = ~value,type = 'scatter', mode = 'none',
fill = 'tozeroy', fillcolor = ~variable, hoverinfo = 'text',
text = ~paste('Date:', WeekStart))
Thanks but how can I make sure that each variable is using the right colour as specified?
– Josh
14 hours ago
see this paragraph : plot.ly/r/line-and-scatter/#custom-color-scales
– Benoît Fayolle
14 hours ago
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%2f55021250%2floop-around-dataframe-columns-and-make-a-plotly-of-the-columns-that-are-present%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
Reshape your Data
to a long vector :
Data <- Data %>% tidyr::gather(key="variable",value="value",-Weeknumber,-WeekStart)
Then call plot_ly and distribute color with the variable
column:
plot_ly(Data,x=~Weeknumber, y = ~value,type = 'scatter', mode = 'none',
fill = 'tozeroy', fillcolor = ~variable, hoverinfo = 'text',
text = ~paste('Date:', WeekStart))
Thanks but how can I make sure that each variable is using the right colour as specified?
– Josh
14 hours ago
see this paragraph : plot.ly/r/line-and-scatter/#custom-color-scales
– Benoît Fayolle
14 hours ago
add a comment |
Reshape your Data
to a long vector :
Data <- Data %>% tidyr::gather(key="variable",value="value",-Weeknumber,-WeekStart)
Then call plot_ly and distribute color with the variable
column:
plot_ly(Data,x=~Weeknumber, y = ~value,type = 'scatter', mode = 'none',
fill = 'tozeroy', fillcolor = ~variable, hoverinfo = 'text',
text = ~paste('Date:', WeekStart))
Thanks but how can I make sure that each variable is using the right colour as specified?
– Josh
14 hours ago
see this paragraph : plot.ly/r/line-and-scatter/#custom-color-scales
– Benoît Fayolle
14 hours ago
add a comment |
Reshape your Data
to a long vector :
Data <- Data %>% tidyr::gather(key="variable",value="value",-Weeknumber,-WeekStart)
Then call plot_ly and distribute color with the variable
column:
plot_ly(Data,x=~Weeknumber, y = ~value,type = 'scatter', mode = 'none',
fill = 'tozeroy', fillcolor = ~variable, hoverinfo = 'text',
text = ~paste('Date:', WeekStart))
Reshape your Data
to a long vector :
Data <- Data %>% tidyr::gather(key="variable",value="value",-Weeknumber,-WeekStart)
Then call plot_ly and distribute color with the variable
column:
plot_ly(Data,x=~Weeknumber, y = ~value,type = 'scatter', mode = 'none',
fill = 'tozeroy', fillcolor = ~variable, hoverinfo = 'text',
text = ~paste('Date:', WeekStart))
answered 15 hours ago
Benoît FayolleBenoît Fayolle
1313
1313
Thanks but how can I make sure that each variable is using the right colour as specified?
– Josh
14 hours ago
see this paragraph : plot.ly/r/line-and-scatter/#custom-color-scales
– Benoît Fayolle
14 hours ago
add a comment |
Thanks but how can I make sure that each variable is using the right colour as specified?
– Josh
14 hours ago
see this paragraph : plot.ly/r/line-and-scatter/#custom-color-scales
– Benoît Fayolle
14 hours ago
Thanks but how can I make sure that each variable is using the right colour as specified?
– Josh
14 hours ago
Thanks but how can I make sure that each variable is using the right colour as specified?
– Josh
14 hours ago
see this paragraph : plot.ly/r/line-and-scatter/#custom-color-scales
– Benoît Fayolle
14 hours ago
see this paragraph : plot.ly/r/line-and-scatter/#custom-color-scales
– Benoît Fayolle
14 hours ago
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.
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%2f55021250%2floop-around-dataframe-columns-and-make-a-plotly-of-the-columns-that-are-present%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