0

I am just starting programming in R. Please help me for this solution to give me an idea.

I want to explore a relationship between distribution of a type of species and elevation to visualize the relation on a graph.

when I plotted the distribution of the species using lat and long information, it looks like scattered points. Now I want to attach elevation data to these points and classify its value with different color on a graph (if the value is 1000-2000, it is red etc.

I just used the following code to make a graph of distribution of the species. plot(species$lon, species$lat)

What I want is add elevation data to the graph where species distributions have been plotted and classify the values of elevation into 5 classes.

R starter
  • 197
  • 12
  • 2
    Welcome to SO! Please make this question *reproducible*. This includes sample code (including listing non-base R packages) and sample data (e.g., `dput(head(x))`). Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Jan 22 '19 at 22:43

1 Answers1

0

You might try using the ggplot2 package instead of the base plot() function. ggplot2 makes it very easy to plot colors based on a third variable like you are describing. You would need to first install tidyverse or just ggplot2.

install.packages('ggplot2')
library(ggplot2) 

ggplot(data = species, 
       aes(x = lon, y = lat, color = elevation)) + 
geom_point()

You may also want to bin the elevation data to transform it from a continuous variable into a categorical variable.

Chris Kiniry
  • 499
  • 3
  • 13