0

Making a 3 month curve for natural gas prices. I'm having some axis issues. I'd like to be able to have the dates show up instead of number of days.

library(ggplot2)
library(Quandl)
library(magrittr)
require(plotly)

#Get first 3 month on the nat gas curve data from Quandl
my_start_date <- "2013-01-05"

gas1<-Quandl("CHRIS/CME_NG1", start_date = my_start_date, type = "xts")
gas2<-Quandl("CHRIS/CME_NG2", start_date = my_start_date, type = "xts")
gas3<-Quandl("CHRIS/CME_NG3", start_date = my_start_date, type = "xts")

#isolate the last prices
gas1a<-gas1[,"Last"]
gas2a<-gas2[,"Last"]
gas3a<-gas3[,"Last"]

p <- merge(as.zoo(gas1a), as.zoo(gas2a), as.zoo(gas3a), all = FALSE)

#3d graph
plot_ly(z = p, type = "surface")%>%
  layout(title = "3 month Nat Gas curve",
         scene = list(
            xaxis = list(title = "Month"),
            yaxis = list(title = "Days"),
            zaxis = list(title = "Price")))

1 Answer 1

1

Are you looking for this?

plot_ly(y=index(p), z = p, type = "surface")%>%
  layout(title = "3 month Nat Gas curve",
         scene = list(
            xaxis = list(title = "Month"),
            yaxis = list(title = "Days", tickangle = 180),
            zaxis = list(title = "Price")))
Sign up to request clarification or add additional context in comments.

3 Comments

thats great- how do I angle the text of the dates?
Great thank you- any idea how I reverse axis labels on x axis? Final one sorry
we usually add autorange = "reversed" , but it looks like it's not working for 3D plot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.