0

Pretty silly but I can't figure out what I'm doing wrong here:

I have a data.frame with 2 columns:

df = data.frame(x = rep(1, 20), y = runif(20, 10,20))

I then want to set x and y as spatial coordinates so I can plot df in a bubble plot. So I try:

coordinates(df) = c("x","y")

But then:

bubble(df)

gives this error:

Error in data.frame(x@data, x@coords) : 
  arguments imply differing number of rows: 0, 20
4

2 回答 2

1

为了使气泡图有意义,您可能应该创建一个SpatialPointsDataFrame.

library(sp)
df <- data.frame(x = rep(1, 20), y = runif(20, 10,20))
data <- data.frame(variable = runif(20))
coordinates(df) <- ~ x + y
out <- SpatialPointsDataFrame(df, data)
bubble(out)

在此处输入图像描述

于 2014-04-28T06:47:54.793 回答
0
library(sp)
set.seed(1)
df = data.frame(x = rep(1, 20), y = runif(20, 10, 20), dummy = rep(0, 20))
coordinates(df) = c("x","y")
bubble(df)

enter image description here

于 2014-04-28T06:13:33.017 回答