如何从ggplotly图中删除选项栏?

问题描述 投票:0回答:1

我有一个使用

shiny
plotly
ggplot2
中渲染的图。但是,我不希望出现悬停时出现的选项栏。有没有办法使用
ggplotly(p)
并删除选项栏?

r ggplot2 shiny plotly shinydashboard
1个回答
33
投票

社区plotly上有一个很好的答案,简短版本:

library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]

使用

ggplotly

p <- ggplot(d, aes(carat, price)) + geom_point()
ggplotly(p) %>% config(displayModeBar = FALSE)

如果您不使用

ggplotly
,您可以这样做:

plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity),
mode = "markers", color = carat, size = carat) %>% config(displayModeBar = FALSE)
© www.soinside.com 2019 - 2024. All rights reserved.