简体   繁体   English

map 上的绘图点,但仅限于特定年份

[英]Plotting points on a map but only by certain year

I am doing GIS stuff in R and only want to plot points from certain years.我在 R 做 GIS 的东西,只想从某些年份获得 plot 积分。 Would I need to superset years, if so can I superset a range of years?我是否需要超集年份,如果需要,我可以超集年份范围吗? I'm not totally sure how to make a reproducible example of this that wouldn't take a ton of time - it seems different than regular plotting.我不完全确定如何制作一个不需要大量时间的可重现示例 - 它似乎与常规绘图不同。

Essentially, how do I only get certain points on the data frame to come up on the map?本质上,我如何才能在 map 上只获得数据帧上的某些点? Subsetting years?子集年?

I have points set up as follows我的积分设置如下

points(x$longitude,y$latitude)

which plots all points, just want a range of years at a time.它绘制所有点,一次只需要几年的范围。 Thanks.谢谢。

When you use the $ operator you are extracting a column of your data.frame x as a vector.当您使用$运算符时,您正在提取 data.frame x的一列作为向量。 A vector can be subset by a logical vector passed to square braces, returning the ith elements where the logical value is TRUE , eg c(TRUE, FALSE, TRUE) passed to c("a", "b", "c") as c("a", "b", "c")[c(TRUE, FALSE, TRUE)] would return a and c .向量可以是传递给方括号的逻辑向量的子集,返回逻辑值为TRUE的第 i 个元素,例如c(TRUE, FALSE, TRUE)传递给c("a", "b", "c")因为c("a", "b", "c")[c(TRUE, FALSE, TRUE)]将返回ac

Logical vectors can be created automatically with logical operations.逻辑向量可以通过逻辑运算自动创建。 The key operators are主要运营商是

  • == is equal to ==等于
  • != is not equal to !=不等于
  • > greater than >大于
  • < less than <小于
  • >= greater than or equal to >=大于或等于
  • <= less than it equal to <=小于等于

And operations can be combined with & (and) and |和运算可以与& (and) 和|结合使用(or), and logic can be reversed using ! (或),并且可以使用! (eg !3<4 would ask is three not less than four?). (例如!3<4会问三小于四吗?)。

As an example, c(1,2,3,4) >= 3 would produce FALSE FALSE TRUE TRUE .例如, c(1,2,3,4) >= 3将产生FALSE FALSE TRUE TRUE

Assuming you have a variable called year in x , you solution would look something like:假设您在x中有一个名为 year 的变量,您的解决方案将类似于:

points(x$longitude[x$year>2005 & x$year<=2010], 
       y$latitude[ x$year>2005 & x$year<=2010)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM