0

In the code below, is it possible to make the legend background semi-transparent? I cannot pass analphavalue toelement_rect()inlegend.backgroundorlegend.box.backgroundto do this. As an example,tm_layout()intmappackage can do this with argumentslegend.bg.color = "white"andlegend.bg.alpha = 0.5.

suppressMessages(library(ggmap))
data(crime)
houston.map <- get_map(location = geocode("Houston"),
                       zoom = 14,
                       maptype = "satellite")
ggmap(houston.map, extent = "device", legend = "topleft") +
  geom_point(aes(x = lon, y = lat, color = offense), data = crime) +
  theme(legend.background = element_rect(fill = alpha("white", 0.7)),
        legend.key = element_rect(color = NA, fill = NA))

Update: Thanks to jazzurro I updated the code to passalpha()inelement_rect(),and the attached picture is how it looks. This answers my question.

enter image description here

Manojit
  • 611
  • 1
  • 8
  • 18
  • 1
    Have you seen [this question](https://stackoverflow.com/questions/16251966/controlling-the-alpha-level-in-a-ggplot2-legend) before? – jazzurro Feb 04 '18 at 15:02
  • @jazzurro That's quick! No I did not see it before, thanks for pointing this out. Let me check it out. – Manojit Feb 04 '18 at 15:04
  • I hope the question helps you! – jazzurro Feb 04 '18 at 15:07
  • 1
    @jazzurro It helped indeed. I updated the post, and now need to fiddle around to make the legend keys more visible. – Manojit Feb 04 '18 at 15:21
  • your post is not reproducible and not clear if you still need help or not – MLavoie Feb 05 '18 at 21:32
  • @MLavoie The post is not reproducible because of my updated code. The answer came from jazzuro's comment (as noted in the update), but I did not know how to accept a comment as an answer. I have now edited my update to this effect. Thanks for pointing this out. – Manojit Feb 05 '18 at 23:48

0 Answers0