2017-11-22 3 views
0

散布図を表す光沢のあるアプリケーションがあります。光沢のあるユーザーがデータフィルタリングを実行すると、データがプロットグラフに表示されます。時々、作成されたデータはすべて負またはすべての正の値になりますが、私は原点(0,0)が表示されるように配置されるようにプロットしたいと考えています。プロット中にプロットする際にプロットする際に起点(0,0)を常に表示する

例:

enter image description here

しかし、私はそれがより多くのことのように最初に見てみたい:

dd <- data.frame(x=c(2,3,6,2), y=c(5,2,7,3)) 
plot_ly(data=dd, x=~x, y=~y, type="scatter", mode="markers") 

与え

enter image description here

任意のアイデアことを行う方法?

答えて

2

使用rangemode:

plot_ly(data=dd, x=~x, y=~y, type="scatter", mode="markers") %>% 
    layout(
    xaxis = list(rangemode = "tozero"), 
    yaxis = list(rangemode = "tozero")) 

enter image description here

これもdd2 <- -1 * ddで動作します:

plot_ly(data=dd2, x=~x, y=~y, type="scatter", mode="markers") %>% 
    layout(
    xaxis = list(rangemode = "tozero"), 
    yaxis = list(rangemode = "tozero")) 

enter image description here

+1

どちらの答えも使えます。@missuseの方が柔軟性があります(プロットを大きくすることができます)が、これは簡単です。私はそれを簡単にするために選択します。ありがとう – Bastien

1

一つは、軸を変更することができ、このようなレイアウトで範囲:

plot_ly(data=dd, x=~x, y=~y, type="scatter", mode="markers") %>% 
    layout(
     xaxis = list(range = c(~min(c(-1,x)), ~max(c(1,x)))), 
     yaxis = list(range = c(~min(c(-1,y)), ~max(c(1,y))))) 

enter image description here

+1

それは良いスタートだが、それはようDD2 < 'で動作するように - だけでなく-1 * dd'。 yaxis = list(範囲= c(〜(x、x))〜 '(x(c(1、x)))ありがとう、 – Bastien

+0

@Bastienそれは良いアプローチです。私は答えを編集しました。 – missuse

関連する問題