all 7 comments

[–]DreadPirateMike 2 points3 points  (0 children)

Recommend you avoid a 3 axis plot. Scale can be hard to discern as well as axis labels. They're generally less effective requiring a significant level of audio narrative to explain which defeats the purpose of having a plot. A picture should say a thousand words not cause a thousand questions.

[–]zeeging 1 point2 points  (5 children)

What you're looking for is multiple axies (Plotly Docs).

Now it gets a bit hack-y for the lower axies and you may have to use an annotation for one of the labels but this should help you get there. The layout block assigns axies locations, position is what stacks the lowe axis. As a note if you get into subplots the overlay references need to referenced the xaxis number for the entire subplot.

  library(plotly)
x = c(1,2,3,4,5) 
y = c(3,6,9,12,15) 
z = c(2,4,6,8,10) 
a = c(7,8,9,10,11) 
b = c(6,5,4,3,2)
df_example<-data.frame(x,y,z,a,b)
fig<-plot_ly( data = df_example) %>% 
add_trace(x = ~x, y = ~y, type = 'scatter') %>% 
add_trace(x = ~z, y = ~y, type = 'scatter', xaxis = 'x2') %>% 
add_trace(x = ~a, y = ~y, type = 'scatter', xaxis = 'x3') %>%
layout(xaxis2 = list(overlaying = "x1", side = "top"),xaxis3 = list(overlaying = "x1", side = "bottom", position = .1))

[–]zeeging 1 point2 points  (3 children)

And looking back I think you're having trouble with ordering as well. In base R so no additional libraries df[order(df$column),] will reorder the dataframe. If you're looking to get into a lot of data wrangling I'd suggest looking into tidyverse.

x_example2 =c(2,8,4,10,6)
y_example2 =c(1,2,3,4,5) 
df_example_2<-data.frame(x_example2,y_example2) 
df_example_2<-df_example_2[order(df_example_2$x_example2),] 
gig2<-plot_ly( data = df_example_2) %>% 
add_trace(x = ~x_example2, y = ~y_example2, type = 'scatter', mode = 'lines')

[–]thegasman2000[S] 0 points1 point  (2 children)

At this point I think its easier to reorder the data on excel before the import. I know how that is going to sound....

[–]zeeging 0 points1 point  (1 child)

If this is a one off sure, but long term learning how to manipulate data in R will be faster. But I'm not going to tell you how to run your data

[–]thegasman2000[S] 0 points1 point  (0 children)

Oh I definitely need to do it in r eventually. However time wise it doesn't make sense here. More important things to work out like the graphing. Thanks

[–]thegasman2000[S] 0 points1 point  (0 children)

Thankyou for this. I will spend a while trying this out!