Ploting map Close.Price in each City Use data GeorgeDell25Mile.csv

1.Library

library(maps)
library(mapdata)
library(tidyverse)
library(lubridate)
library(ggplot2)

2.Read data from directory

# Please change with your directory use data GeorgeDell25Mile.csv

sg <- read.csv("d:/YOUR-DIRECTORY/GeorgeDell25Mile.csv")
head(sg)
##   Street.Number   Street.Name          City State.Or.Province   Zip Latitude
## 1          1420   Ron Whicker       Catawba    North Carolina 28609 35.67607
## 2          4991     White Oak        Lenoir    North Carolina 28645 35.90588
## 3          5691 Nc Highway 18     Morganton    North Carolina 28655 35.68110
## 4          2396     Dry Ponds Granite Falls    North Carolina 28630 35.80214
## 5           322      Boyd Fox  Taylorsville    North Carolina 28681 35.87862
## 6           643  Kendell Town      Ferguson    North Carolina 28624 36.08015
##   Longitude Close.Date Close.Price DOM Status Off.Market.Date List.Price
## 1 -80.98673  9/30/2021      830000  18 Closed       9/30/2021     850000
## 2 -81.66048   9/4/2020      517500  85 Closed        9/4/2020     499000
## 3 -81.56414  10/7/2020      498000   3 Closed       10/7/2020     489900
## 4 -81.49068  3/15/2021      480000  39 Closed       3/15/2021     499000
## 5 -81.26226  9/29/2020      450000  11 Closed       9/29/2020     459900
## 6 -81.42162  6/14/2021      445000 186 Closed       6/14/2021     450000
##   Original.List.Price Above.Grade.Finished.Area Lot.Size.Area Lot.Size.Units
## 1              850000                      2210          5.20             NA
## 2              594900                      1365         11.76             NA
## 3              489000                      1295         15.74             NA
## 4              499000                      2510         10.00             NA
## 5              459900                       861         13.70             NA
## 6              480000                      1427         37.03             NA
##   Zoning Year.Built Sq.Ft.Garage Beds.Total Baths.Total
## 1              2019          505          2           3
## 2              2018          859          2           3
## 3              2004          645          2           3
## 4              1981         1012          2           4
## 5              1984         1792          2           2
## 6              2004           NA          2           2

3. Select data use for ploting

sg1 <- sg %>% select(Close.Date,Close.Price,Latitude,Longitude,City)
head(sg1)
##   Close.Date Close.Price Latitude Longitude          City
## 1  9/30/2021      830000 35.67607 -80.98673       Catawba
## 2   9/4/2020      517500 35.90588 -81.66048        Lenoir
## 3  10/7/2020      498000 35.68110 -81.56414     Morganton
## 4  3/15/2021      480000 35.80214 -81.49068 Granite Falls
## 5  9/29/2020      450000 35.87862 -81.26226  Taylorsville
## 6  6/14/2021      445000 36.08015 -81.42162      Ferguson

4.Convert as Date

sg1$Close.Date <- as.Date(sg1$Close.Date, "%m/%d/%Y")

min(sg1$Latitude)
## [1] 35.48246
max(sg1$Latitude)
## [1] 36.16847
min(sg1$Longitude)
## [1] -81.70686
max(sg1$Longitude)
## [1] -80.86962

5. Check value Close.Price

min(sg1$Close.Price)
## [1] 17500
max(sg1$Close.Price)
## [1] 830000

6. Result Date

head(sg1)
##   Close.Date Close.Price Latitude Longitude          City
## 1 2021-09-30      830000 35.67607 -80.98673       Catawba
## 2 2020-09-04      517500 35.90588 -81.66048        Lenoir
## 3 2020-10-07      498000 35.68110 -81.56414     Morganton
## 4 2021-03-15      480000 35.80214 -81.49068 Granite Falls
## 5 2020-09-29      450000 35.87862 -81.26226  Taylorsville
## 6 2021-06-14      445000 36.08015 -81.42162      Ferguson

7. Ploting map Close.Price in each City

pn1 <- ggplot(data=sg1, aes(x=Longitude, y=Latitude))+#, fill= City))+#, group=group)) + 
  #geom_polygon(color = "white") + 
  geom_point(color="blue", alpha = 0.3, size = (sg1$Close.Price)*0.00001)+
  ggtitle('Close.Price VS City')+
  coord_fixed(1.5)+
  theme(panel.background = element_rect(fill = "azure1", colour = "azure1")) +
  geom_text(aes(x=Longitude, y= Latitude, label=City),
            color = "gray20", check_overlap = T, size = 3)+
  theme_classic()
pn1

8. Order City VS Close.Price

sg2 <- sg1[order(sg1$Close.Price),]

head(sg2)
##     Close.Date Close.Price Latitude Longitude      City
## 264 2017-11-21       17500 35.91146 -81.61423    Lenoir
## 265 2017-11-21       17500 35.91146 -81.61423    Lenoir
## 261 2017-12-22       18500 35.86708 -81.66091 Morganton
## 262 2017-12-22       18500 35.86708 -81.66091 Morganton
## 263 2017-12-22       18500 35.86708 -81.66091 Morganton
## 260 2019-02-06       23000 35.97265 -81.57208    Lenoir
tail(sg2)
##   Close.Date Close.Price Latitude Longitude          City
## 6 2021-06-14      445000 36.08015 -81.42162      Ferguson
## 5 2020-09-29      450000 35.87862 -81.26226  Taylorsville
## 4 2021-03-15      480000 35.80214 -81.49068 Granite Falls
## 3 2020-10-07      498000 35.68110 -81.56414     Morganton
## 2 2020-09-04      517500 35.90588 -81.66048        Lenoir
## 1 2021-09-30      830000 35.67607 -80.98673       Catawba

9. Explanation

-1. From the map(pn1) by looking at the blue circle, the bigger the circle, the greater the value of the City and Close.Price at a location
-2. From tail(sg2), we can see the certain City with biggest value of Close.Price, Catawba 830000, Lenoir 517500, Morganton 498000