
上QQ阅读APP看书,第一时间看更新
Importing point data from Excel
We have many arbitrary measures collected for different districts of Bangladesh along with their point coordinates; these measures contain both numeric and categorical values.
Now, we will import this data into R using read.csv() as follows:
bd_val = read.csv("F:/Hands-on-Geospatial-Analysis-Using-R-and-QGIS/Chapter02/Data/r_val.csv", stringsAsFactors = FALSE)
We check the structure of this dataset bd_val using str():
str(bd_val)
We get the following output:

We see that the type of bd_val is dataframe. Now, we convert this into SpatialPointsDataFrame by using coordinates() and by specifying which columns contain the longitude and latitude of these points.
# Convert it into SpatialPointsDataframe
coordinates(bd_val) = c("lon", "lat")
str(bd_val)

Now, plot this using plot():
plot(bd_val, col = "blue", pch = 19)
Now, we get the following map with blue dot for each point:
