Search code examples
rfiltercriteriaspatial

Subset original data and spatial data


I have created a spatial points data frame (df_sp$Latitude) and would like to plot a graph comparing against variables in my original data frame (df$Abundance).

However, I would like to filter all values that are greater than zero from df$abundance. How would I filter these out, and the corresponding variable within df_sp$latitude, without ending up with this error that I am currently getting?

Error in xy.coords(x, y, xlabel, ylabel, log) : 
'x' and 'y' lengths differ

I'm able to generate a simple plot like this:

plot(df_sp$Latitude, df$Abundance)

However, I'm unsure as to how to subset my data to include abundance values greater than zero.


Solution

  • df2 <- cbind(df_sp$Latitude, df$Abundance)
    df2 <- df2[df2$Abundance > 0,:]
    plot(df2)