In R, how to make dots transparent while using scale_size in ggplot2?
Asked Answered
T

2

7

This equation leads from my previous question. I want to plot dots that represent total population and so far I used scale_size to make dots' size relative to its total population.

But, I want to make these dots transparent because the dots are covering the map. I am, however, open to other options as long as the message I am trying to send is clear. enter image description here

# load required packages
library(ggmap)
library(ggplot2)

# query map of Birmingham, AL
al1 <- get_map(location = c(lon = -86.304474, lat = 32.362563), zoom = 11,
       source = "osm", maptype = 'terrain')

al1MAP <- ggmap(al1)+ geom_point(data=quote_bmh, 
          aes(x=IntPtLon, y=IntPtLat, size=TotPop, colour="gold2"),
          colour="gold2") + scale_size(range=c(0,15))
Tiffanitiffanie answered 26/4, 2012 at 14:49 Comment(1)
An alternative can be to interpolate the population points using e.g. inverse distance weighted interpolation (idw in gstat), kriging (e.g. automap), or some kernel method (i.e. 2d density).Alimentation
A
10

To use a uniform transparency, just add alpha = 0.3 to geom_point. alpha can be between 0 and 1, depending on the amount of transparency you want. If you want to make you transparency depend on a variable, just add alpha = var_name to the mapping argument (the aes bit), where var_name is the column name of the variable you want to use for transparency.

Alimentation answered 26/4, 2012 at 14:51 Comment(4)
Dang that Paul is quick, saw it and went to post and bam he's answered. +1Beanie
Hahah, I first typed the first part of the answer, than edited to add more detail. These kinds of questions are answered far too quickly, so I needed to be fast :).Alimentation
Wow, you answered so fast that I have to wait ten min to accept your answer. Thanks a lot!Tiffanitiffanie
Great I could help :), good way to spend some time waiting for the EGU poster session to begin :)Alimentation
A
5

Another alternative is to use hollow points, e.g. geom_point(shape = 21). That would make the map directly under the point quite readable while making the edges of the points distinctly visible.

(Unfortunately, my employer blocks the Google API, so I can't post the result)

Axletree answered 26/4, 2012 at 18:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.