{"action":"reopened","issue":{"url":"https://api.github.com/repos/ropensci/plotly/issues/1103","repository_url":"https://api.github.com/repos/ropensci/plotly","labels_url":"https://api.github.com/repos/ropensci/plotly/issues/1103/labels{/name}","comments_url":"https://api.github.com/repos/ropensci/plotly/issues/1103/comments","events_url":"https://api.github.com/repos/ropensci/plotly/issues/1103/events","html_url":"https://github.com/ropensci/plotly/issues/1103","id":251409246,"number":1103,"title":"adding points to a surface reverses x and y axis","user":{"login":"romunov","id":544571,"avatar_url":"https://avatars2.githubusercontent.com/u/544571?v=4","gravatar_id":"","url":"https://api.github.com/users/romunov","html_url":"https://github.com/romunov","followers_url":"https://api.github.com/users/romunov/followers","following_url":"https://api.github.com/users/romunov/following{/other_user}","gists_url":"https://api.github.com/users/romunov/gists{/gist_id}","starred_url":"https://api.github.com/users/romunov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romunov/subscriptions","organizations_url":"https://api.github.com/users/romunov/orgs","repos_url":"https://api.github.com/users/romunov/repos","events_url":"https://api.github.com/users/romunov/events{/privacy}","received_events_url":"https://api.github.com/users/romunov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-19T08:03:05Z","updated_at":"2017-08-19T10:04:06Z","closed_at":null,"body":"In trying to replicate some 3D marginal plots of a model, I notice that `plot_ly` swaps axes when adding points.\r\n\r\nWhen using `persp`, I get a figure which I consider correct. `meshout` changes with size, but not distance.\r\n\r\n![mesh](https://user-images.githubusercontent.com/544571/29485681-1d30bfea-84d6-11e7-98b8-448ed13bbd5d.jpeg)\r\n\r\nbut when mapping `size` and `distance` to x and y respectively, axes appear to be switched.\r\n\r\n![incorrect_plotly](https://user-images.githubusercontent.com/544571/29485687-4ace4bc0-84d6-11e7-8d62-df51cd2e88bb.jpeg)\r\n\r\nWhen manually switching them, plot appears fine.\r\n\r\n![correct_plotly](https://user-images.githubusercontent.com/544571/29485689-54bbcd1a-84d6-11e7-9ffd-f25490b9226a.jpeg)\r\n\r\nIs this something you guys can look into? Below is a fully working example.\r\n\r\n```r\r\nlibrary(plotly)\r\nlibrary(ggplot2)\r\nlibrary(reshape2)\r\nlibrary(rgl)\r\n\r\nN <- 50\r\nB0 <-  1.2\r\nB1 <-  1.5\r\nB2 <- -0.5\r\n\r\nset.seed(357)\r\ncount <- rpois(N, 10)\r\n\r\ndistance <- seq(-0.5, 0.5,,length(count))\r\nsize <- (log(count) - B0 - B2 * distance) / B1\r\nxy <- data.frame(count, size, distance)\r\n\r\nmdl <- glm(count ~ size * distance, family = poisson(link = log), data = xy)\r\nsummary(mdl)\r\n\r\nggplot(xy, aes(x = size, y = count, color = distance)) +\r\n  geom_point()\r\n\r\nnpts <- 50\r\ns.size <- seq(from = min(xy$size), to = max(xy$size), length.out = npts)\r\ns.dist <- seq(from = min(xy$distance), to = max(xy$distance), length.out = npts)\r\nmesh <- expand.grid(\r\n  size = s.size,\r\n  distance = s.dist\r\n)\r\nmesh$count <- predict(mdl, newdata = mesh, type = \"response\")\r\nhead(mesh)\r\n\r\nmeshout <- as.matrix(\r\n  dcast(mesh, formula = size ~ distance, value.var = \"count\")[, -1]\r\n)\r\n\r\npmat <- persp(x = s.size, y = s.dist, z = meshout, # size and distance mapped OK\r\n      theta = 0, phi = 30,\r\n      col = \"grey90\", border = \"grey50\")\r\npoints(trans3d(x = xy$size, y = xy$dist, z = xy$count, pmat = pmat))\r\n\r\nplot3d(x = xy$size, y = xy$distance, z = xy$count) # check, distance and size are plotted correctly\r\n# https://stackoverflow.com/questions/5468280/scale-a-series-between-two-points#comment49916403_5468527\r\nrange02 <- function(x, newMin, newMax){ (x - min(x))/(max(x)-min(x)) * (newMax - newMin) + newMin }\r\n\r\nxy$scaled_size <- range02(xy$size, newMin = 0, newMax = 50)\r\nxy$scaled_distance <- range02(xy$distance, newMin = 0, newMax = 50)\r\n\r\n# size and distance swapped\r\nplot_ly(z = ~ meshout) %>% \r\n  add_surface(name = \"Incorrect mapping of x and y\") %>%\r\n  add_markers(data = xy, x = ~scaled_size, y = ~scaled_distance, z = ~count,\r\n              marker = list(size = 5, color = \"black\"), name = \"Incorrect mapping of x and y\") \r\n\r\n# when switching mapping of x and y, plots fine\r\nplot_ly(z = ~ meshout) %>% \r\n  add_surface(name = \"Incorrect mapping of x and y\") %>%\r\n  add_markers(data = xy, x = ~scaled_distance, y = ~scaled_size, z = ~count,\r\n              marker = list(size = 5, color = \"black\"), name = \"Incorrect mapping of x and y\")\r\n```"}}
{"actor":{"display_login":"romunov"}}