You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Geom_Point在ggmap中尺寸与颜色比例不符问题求助

Troubleshooting Geom_Point Size & Color Mismatch in London Crime Map (R)

Hey there, let's break down why your geom_point might not be scaling correctly with your crime data. From what you've shared, here are the most likely culprits and actionable fixes:

Your Provided Code Snippet

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...  # Incomplete code here

Common Issues & Solutions

  • Missing explicit aesthetic mapping to crime data
    If you're using ggmap (since you called get_googlemap), you need to explicitly link the size and color parameters in geom_point to your numeric crime variable (e.g., a column like Total_Robberies or Crime_Rate in LondonRob). Without this, geom_point uses fixed default values instead of scaling with your data.

    Example fix:

    # First, merge geocoded coordinates with your crime data
    locs_geo <- geocode(Areas)
    LondonRob <- cbind(LondonRob, locs_geo)
    
    # Use ggmap + ggplot2 layers for proper scaling
    ggmap(London_map) +
      geom_point(data = LondonRob, aes(x = lon, y = lat, size = Total_Robberies, color = Total_Robberies)) +
      scale_size_continuous(range = c(2, 10))  # Adjust range to fit your map's zoom level
      scale_color_viridis_c(option = "plasma")  # Accessible continuous color scale
    
  • Mixing base R plot() with ggplot2 geom_point
    Your current code uses base R's plot(London_map), but geom_point is a ggplot2 function. These two systems don't play well together—you need to use ggmap() to render the map, then add ggplot2 layers on top.

  • Unmerged geocoded coordinates
    If locs_geo isn't combined with your LondonRob data frame, your crime metrics won't be linked to the correct geographic points. Always merge the geocoded lon/lat values back into your main dataset before plotting.

  • Using discrete scales for numeric data
    If your crime variable is numeric, using discrete size/color scales will break the proportional mapping. Stick to scale_size_continuous and scale_color_continuous (or viridis scales) for numeric data.

If you can share the full code (especially the part where you add geom_point) and details about your crime data column, I can help refine this further!

内容的提问来源于stack exchange,提问作者JohnPorter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:22:04