# Adding alpha to hover in R - can it be done?

**URL:** <https://community.plotly.com/t/adding-alpha-to-hover-in-r-can-it-be-done/56126>\
**Category:** Plotly R\
**Created:** [August 31, 2021, 8:22pm UTC](https://community.plotly.com/t/adding-alpha-to-hover-in-r-can-it-be-done/56126 "2021-08-31T20:22:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcorbett](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@rcorbett](https://community.plotly.com/u/rcorbett)\
**Post date:** [August 31, 2021, 8:22pm UTC](https://community.plotly.com/t/adding-alpha-to-hover-in-r-can-it-be-done/56126/1 "2021-08-31T20:22:03Z")

</div>

Hi folks.  
Newb here.

I am learning how to create plotly figures using the ggplotly route. I was pleased to see how easily I could generate an interactive plot from my previously created ggplot figure. However, after that very expeditious experience I’ve been slowed to crawl as I try to tweak the resulting plotly figure.

 ![Screen Shot 2021-08-31 at 1.15.46 PM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/c/9/c918ea1c9f611ea96f2b3d999c7577644d4d36f2.png)

As you can hopefully see in the attached image, the hover that comes up obscures the points behind it. is there a way to set the alpha of the hover box to either match that of the points it references, or to a constant value?

```auto
G = ggplot(T, aes(x=fct_reorder(Tea, median_rating, median), y=Rating, color=Brand, fill=Brand,
                  text = paste(
                        "Tea: ", Tea, "\n",
                        "Brand: ", Brand, "\n",
                        "Tea Median Score: ", median_rating, "\n",
                        "Score: ", Rating, "\n",
                        sep = "")
                  )
           ) +
    geom_point(size=2.5, shape=21, alpha=0.3) +
    scale_color_brewer(palette="Set1", direction = 1) +
    scale_fill_brewer(palette="Set1", direction = 1) +
    coord_flip() +
    labs(x="Tea", y="Rating") +
    ggtitle('Herbal Tea Ratings') +
    theme_minimal() +
    theme(
        plot.title = element_text(hjust = 0.5),
        plot.subtitle = element_text(hjust = 0.5)
    )
#set up margins
m <- list(
  l = 50,
  r = 50,
  b = 50,
  t = 100,
  pad = 4
)

P = plotly::ggplotly(G, tooltip = "text")
config(P, displaylogo = FALSE) %>%
    layout(responsive=TRUE, margin = m)

```

thanks,  
Richard

---

<div class="post-metadata">

**Author:** ![ismirsehregal](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/ismirsehregal/32/6794_2.png) [@ismirsehregal](https://community.plotly.com/u/ismirsehregal)\
**Post date:** [September 6, 2021, 7:28am UTC](https://community.plotly.com/t/adding-alpha-to-hover-in-r-can-it-be-done/56126/2 "2021-09-06T07:28:05Z")

</div>

Currently setting the opacity for a hoverlabel isn’t possible. `hoverlabel.opacity` is part of an [open issue](https://github.com/plotly/plotly.js/issues/2342) regarding plotly.js.

The only [workaround I am aware of](https://stackoverflow.com/a/67725337/9841389) is setting `hovermode = 'x unified'`.

You’ll need to adapt your `layout` call:

`[...] %>% layout(responsive=TRUE, margin = m, hovermode = 'x unified', hoverlabel = list(bgcolor = 'rgba(255,255,255,0.75)', font = list(color='black')))`
