【发布时间】:2014-05-27 10:45:50
【问题描述】:
嗨,我有很多这样的数据框
id oldid yr mo dy lon lat
1 01206295 Aberfeldy 1885 3 22 -127.1 -31.78
2 05670001 05670005 1885 3 22 -4.38 49.15
3 06279 06279 1885 3 22 -123.5 37.5
4 106251 06323 1885 3 22 178.5 19.5
5 58FFF3618 58FFF3618 1885 3 22 -0.73 69.73
6 Achille.F Achille.F 1885 3 22 -35.62 -2.98
存储在不同的文件myfiles 中,我正在尝试使用根据 id 值选择的颜色为每个点绘制 (lon,lat) 点。到目前为止,我都是这样做的
for (i in 1:length(myfiles)){
colnames(myfilesContent[[i]]) <-c("id","oldid","yr","mo","dy","lon","lat")
p <- ggplot() + geom_polygon(data=world_map,aes(x=long, y=lat,group=group))
myfilesContent[[i]]$lon <- as.numeric(myfilesContent[[i]]$lon)
myfilesContent[[i]]$lat <- as.numeric(myfilesContent[[i]]$lat)
p + geom_point(data=myfilesContent[[i]], aes(x=lon, y=lat, fill=as.factor(id)), size = 4, shape = 21, show_guide=FALSE)
print(p)
}
无论如何,我不确定如果一个 id 在不同的文件中,它将被分配相同的颜色
非常感谢
【问题讨论】:
-
这取决于你如何分割数据框。如果您将其按
id拆分(就像我在previous answer 中对您的问题所做的那样),那么您应该没有问题。 -
嗨,谢谢,但我的文件不是按 id 而是按日期拆分的……我必须做两个 for 循环吗?
-
myfiles 包含每个日期的原始数据帧..