【问题标题】:"non-numeric argument to binary operator" when using geom_point + aes function使用 geom_point + aes 函数时的“二元运算符的非数字参数”
【发布时间】:2019-03-27 22:46:26
【问题描述】:

我正在尝试在地图“UKmap”上绘制英国每个行政港口“AdminPort”中的船只数量“n”,在我的代码中,我将大小设置为等于 n(船只数量),所以点绘制在地图上取决于船只的数量。即使 n 是一列数字,我也会不断收到错误消息:

"UKmap + geom_point 中的错误(aes(x = Longitude, y = Latitude), size = 4, : 二元运算符的非数字参数
另外:警告信息: “+”的不兼容方法(“Ops.raster”、“+.gg”)

我做错了什么?我在下面添加了我的代码和 30x4 tibble (AdminPortCLL)。

# A tibble: 30 x 4
       lon   lat AdminPort       n
     <dbl> <dbl> <chr>       <int>
 1 -2.10    57.1 ABERDEEN       70
 2 -4.63    55.5 AYR            77
 3 -5.93    54.6 BELFAST       187
 4 -3.52    50.4 BRIXHAM       184
 5 -2.96    57.7 BUCKIE         69
 6 -5.61    55.4 CAMPBELTOWN    97
 7 -2.09    55.9 EYEMOUTH       73
 8 -3.01    53.9 FLEETWOOD      92
 9 -2.02    57.7 FRASERBURGH   120
10 -0.0736  53.6 GRIMSBY        56
# ... with 20 more rows
UKmap +
  geom_point(aes(x = Longitude, y = Latitude), 
             size =  n, data = AdminPortCLL) + 
  theme(legend.position = "top")

【问题讨论】:

  • 您可能希望在aes 中使用size = n
  • 当我在 aes 中移动尺寸时,我仍然收到相同的错误消息。
  • 什么是 UKmap - 没有这个问题就无法重现。如果您将 UKmap 替换为 ggplot(),您的代码是否有效?

标签: r ggplot2


【解决方案1】:

假设您使用的是ggmap.... 您的 UKmap 可能仍然只是一张图片。在添加点之前,将其转换为ggmap 对象:

UKmap <- ggmap(UKmap)

另外,您需要使用AdminPortCLL tibble 中的列名:

UKmap +
  geom_point(aes(x = lon, y = lat), 
             size =  n, data = AdminPortCLL) + 
  theme(legend.position = "top")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 2021-03-24
    相关资源
    最近更新 更多