Example 4 using sp (Spatial Data Manipulation and Visualization)
R
# Load the sp package library (sp) # Create a simple SpatialPointsDataFrame coords <- data.frame ( x = c (0, 1, 2), y = c (0, 1, 0) ) points <- SpatialPoints (coords) df <- data.frame (ID = c ( "A" , "B" , "C" )) spdf <- SpatialPointsDataFrame (points, df) # Plot the SpatialPointsDataFrame plot (spdf, pch = 19, col = "red" , main = "Simple SpatialPointsDataFrame" ) |
Output:
In this example, we use the sp package to create a simple SpatialPointsDataFrame. We define coordinates (x and y) for three points, create a data frame for attribute data, and then combine them into a SpatialPointsDataFrame. Finally, we use the plot() function to visualize the points. We specify the pch argument to set the point type, the col argument to set the point color, and add a title to the plot.
Geospatial Data Analysis with R
Geospatial data analysis involves working with data that has a geographic or spatial component. It allows us to analyze and visualize data in the context of its location on the Earth’s surface. R Programming Language is a popular open-source programming language, that offers a wide range of packages and tools for geospatial data analysis.