Jor*_*ama 6 r ggplot2 shiny plotly
我试图在R中创建一个没有显示异常值的情节箱图,我在官方页面中找到了这个链接:https://plot.ly/ggplot2/box-plots/#outliers
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
Run Code Online (Sandbox Code Playgroud)
似乎是一个错字。也许该示例未更新以考虑对象结构中的某些更改。打电话后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)
})
Run Code Online (Sandbox Code Playgroud)
使一切按预期工作: