2017-04-19 98 views
4

私が異常値を示してdoesntのRでplotly箱ひげ図を作成しようとしています、と私はplotlyの公式ページでこのリンクを見つけた: https://plot.ly/ggplot2/box-plots/#outliers箱ひげ図から外れ値を削除し、plotly

library(plotly) 
set.seed(123) 

df <- diamonds[sample(1:nrow(diamonds), size = 1000),] 

p <- ggplot(df, aes(cut, price, fill = cut)) + 
geom_boxplot(outlier.shape = NA) + 
ggtitle("Ignore outliers in ggplot2") 

# Need to modify the plotly object and make outlier points have opacity equal 
to 0 
p <- plotly_build(p) 

p$data <- lapply(p$data, FUN = function(x){ 
x$marker = list(opacity = 0) 
return(x) 
}) 


# Create a shareable link to your chart 
# Set up API credentials: https://plot.ly/r/getting-started 
chart_link = plotly_POST(p, filename="geom_boxplot/outliers") 
chart_link 

問題があることです自分のウェブページや私のコンソールでは、異常値はまだ表示されています。 enter image description here これは何らかのバグですか?

+0

として、バグはおそらく固定されます。 'geom_boxplot(outlier.shape = NA)'は、外れ値のないボックスプロットを生成します。 – Ufos

答えて

1

タイプミスのようです。おそらく、この例は、オブジェクト構造のいくつかの変更を説明するために更新されていない可能性があります。 p <- plotly_build(p)を呼び出した後、p$dataが存在しないことがわかりますが、p$x$dataがあります。だから、次のようにlapplyの呼び出しを変更:

p$x$data <- lapply(p$x$data, FUN = function(x){ 
x$marker = list(opacity = 0) 
return(x) 
}) 

は、意図したとおりにすべての作業を行います、時間の経過

enter image description here

+0

これは異常値だけを透明にするのではなく、実際にすべての点を透明にします。 geom_jitterレイヤーでは、ポイントは表示されません。外れ値の設定に関して 'p $ x $ data $ marker $ outliercolor'しか見つけることができませんでしたが、期待どおりには動作しません。私は他の点を見たいと思っていますか? –

関連する問題