JohnPorter
JohnPorter

Reputation: 11

Geom_Point not portioning sizes on ggmap correctly

So I am plotting crime levels onto London, however the sizes and colours are not proportionate to the figures I am using. I will leave the code and graphic below, if anyone can give me an explanation as to why this is happening i would really appreciate it. Thanks

London <- c(lon=-0.1278, lat=51.5074)
London_map <- get_googlemap(center = London, zoom = 10)
plot(London_map)
LondonRob <- read.csv("Rob London.csv")
Areas <- as.character(LondonRob$ï..Borough)
locs_geo <- geocode(Areas)
df <- cbind(LondonRob, locs_geo)

Map <- ggmap(London_map) + 
  geom_point(data = df, 
             aes(x = lon, y = lat,
                 size = LondonRob$X2012.13, 
                 color = LondonRob$X2012.13))  

Map1 <- Map + labs(color="Robbery")
Map1 <- Map1 + labs(size="Figures")
Map1

London Robbery Figures 2012

Upvotes: 0

Views: 689

Answers (1)

Axeman
Axeman

Reputation: 35307

scale_size_continuous, which is the default when mapping a continuous variable to size, uses the range argument to determine the scale. By default, this is c(1, 6), and ggplot will translate the variation in the X2012.13 variable to a range from size 1 to size 6.

In many scenarios, with points, you don't want this default. Instead you want to able to compare the sizes directly, with 0 being no point at all. Then you can use scale_size_area instead.

This has the added benefit the area is scaled instead of the radius, which performs better visually.

In addition, you very likely should not be doing

aes(x = lon, y = lat, size = LondonRob$X2012.13, color = LondonRob$X2012.13) 

but rather rather

aes(x = lon, y = lat, size = X2012.13, color = X2012.13) 

As a general rule, never use $ inside aes, things can go horribly wrong, without any errors or warnings.

Upvotes: 1

Related Questions