rplotly

Log axis in ploy_ly for R


I'm trying to make a 3D mesh plot with log x and y axis using plot_ly.

library(plotly)

help_plot_data <- data.frame(A_Conc = rep(c(1:100), times = 100),
                             B_Conc = rep(c(1:100), each = 100))
help_plot_data$Response <- help_plot_data$A_Conc*help_plot_data$B_Conc

plot_model <- plot_ly(
  help_plot_data, x= ~A_Conc, y= ~B_Conc, z = ~Response, 
  type='mesh3d', intensity = ~Response,
  colors= colorRamp(rainbow(5))) %>% 
  layout(plot_model, 
         xaxis = list(range = c(1, 100),
                      type = "log"),
         yaxis = list(range = c(1, 100),
                      type = "log"))
plot_model

Gives me this plot: No log axis!

I've also tried scale_log_10(), which I couldn't get to work. Any help much appreciated.


Solution

  • Setting the scene in the layout function results in a basic log plot. You will probably want to adjust the tick marks on the x and y axis.

    library(plotly)
    
    help_plot_data <- data.frame(A_Conc = rep(c(1:100), times = 100),
                                 B_Conc = rep(c(1:100), each = 100))
    help_plot_data$Response <- help_plot_data$A_Conc*help_plot_data$B_Conc
    
    plot_model <- plot_ly(
      help_plot_data, x= ~A_Conc, y= ~B_Conc, z = ~Response, 
      type='mesh3d', intensity = ~Response,
      colors= colorRamp(rainbow(5))) |> 
      layout(scene = list(
             xaxis = list(type = "log"),
             yaxis = list(type = "log")))
    
    
    plot_model