plotly / plotly/plotly.R

adding points to a surface reverses x and y axis

オープン
#1,103 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
R
スター
2.7k
フォーク
641
PR マージ指標
30日以内にマージされた PR はありません

説明

In trying to replicate some 3D marginal plots of a model, I notice that plot_ly swaps axes when adding points.

When using persp, I get a figure which I consider correct. meshout changes with size, but not distance.

mesh

but when mapping size and distance to x and y respectively, axes appear to be switched.

incorrect_plotly

When manually switching them, plot appears fine.

correct_plotly

Is this something you guys can look into? Below is a fully working example.

library(plotly)
library(ggplot2)
library(reshape2)
library(rgl)

N <- 50
B0 <-  1.2
B1 <-  1.5
B2 <- -0.5

set.seed(357)
count <- rpois(N, 10)

distance <- seq(-0.5, 0.5,,length(count))
size <- (log(count) - B0 - B2 * distance) / B1
xy <- data.frame(count, size, distance)

mdl <- glm(count ~ size * distance, family = poisson(link = log), data = xy)
summary(mdl)

ggplot(xy, aes(x = size, y = count, color = distance)) +
  geom_point()

npts <- 50
s.size <- seq(from = min(xy$size), to = max(xy$size), length.out = npts)
s.dist <- seq(from = min(xy$distance), to = max(xy$distance), length.out = npts)
mesh <- expand.grid(
  size = s.size,
  distance = s.dist
)
mesh$count <- predict(mdl, newdata = mesh, type = "response")
head(mesh)

meshout <- as.matrix(
  dcast(mesh, formula = size ~ distance, value.var = "count")[, -1]
)

pmat <- persp(x = s.size, y = s.dist, z = meshout, # size and distance mapped OK
      theta = 0, phi = 30,
      col = "grey90", border = "grey50")
points(trans3d(x = xy$size, y = xy$dist, z = xy$count, pmat = pmat))

plot3d(x = xy$size, y = xy$distance, z = xy$count) # check, distance and size are plotted correctly
# https://stackoverflow.com/questions/5468280/scale-a-series-between-two-points#comment49916403_5468527
range02 <- function(x, newMin, newMax){ (x - min(x))/(max(x)-min(x)) * (newMax - newMin) + newMin }

xy$scaled_size <- range02(xy$size, newMin = 0, newMax = 50)
xy$scaled_distance <- range02(xy$distance, newMin = 0, newMax = 50)

# size and distance swapped
plot_ly(z = ~ meshout) %>% 
  add_surface(name = "Incorrect mapping of x and y") %>%
  add_markers(data = xy, x = ~scaled_size, y = ~scaled_distance, z = ~count,
              marker = list(size = 5, color = "black"), name = "Incorrect mapping of x and y") 

# when switching mapping of x and y, plots fine
plot_ly(z = ~ meshout) %>% 
  add_surface(name = "Incorrect mapping of x and y") %>%
  add_markers(data = xy, x = ~scaled_distance, y = ~scaled_size, z = ~count,
              marker = list(size = 5, color = "black"), name = "Incorrect mapping of x and y")

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

plot_ly()、add_surface()、add_markers()を使用する再現可能なRの例から始め、軸のマッピングをpersp()およびplot3d()と比較します。マーカーのx値とy値に対して、サーフェスの座標がどのように設定されるかを追跡します。サーフェスと追加された点が、手動で入れ替えることなく同じサイズ軸と距離軸を使用すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
r
領域
data-visualization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。