Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204922

Use tooltip with plotly_build() to prevent hover text from being displayed twice

$
0
0

I have the dataframe below:

etf_id<-c("a","b","c","d","e","a","b","c","d","e","a","b","c","d","e")
factor<-c("A","A","A","A","A","B","B","B","B","B","C","C","C","C","C")
normalized<-c(-0.048436801,2.850578601,2.551666490,0.928625186,-0.638111793,
              -0.540615895,-0.501691539,-1.099239823,-0.040736139,-0.192048665,
              0.198915407,-0.092525810,0.214317734,2.550478998,0.024613778)
df<-data.frame(etf_id,factor,normalized)

and I have managed to remove outliers with a plotly_build() method:

p<-df %>% 
  ggplot(aes(factor, normalized, color = factor)) +
  geom_boxplot(outlier.color = NA,outlier.size = 0,outlier.shape = NA) +
  coord_cartesian(ylim = quantile(df$normalized, c(0.01, 0.99), na.rm = T)) +
  geom_point(data = df, 
             aes(x = factor, y = normalized, shape = etf_id, color = etf_id,
                 text = paste("ticker: ", etf_id, "<br> factor: ", factor, "<br> normalized: ", round(normalized, 4), sep = "")), 
             size = 2)

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

for(i in 1:length(p$x$data)) {
  p$x$data[[i]]$marker$opacity = 0
}

p

The issue is that the hover text is displayed twice and the plotly_build() does not accept tooltip argument to fix it.

over text from displaying twice.


Viewing all articles
Browse latest Browse all 204922

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>