I have an error in my codes which is: Error: Fill argument neither colors nor valid variable name(s)
In the following, I describe how I get this error. Indeed, I have two sets of data and assigned them into two variables named Caifornia_shp and Houses. The information of these two variables are as follow:
head(California_shp)
NAME
1 Alameda
2 Alpine
3 Amador
4 Butte
5 Calaveras
6 Colusa
head(Houses)
houseValue income houseAge rooms bedrooms population households latitude longitude
1 452600 8.3252 41 880 129 322 126 37.88 -122.23
2 358500 8.3014 21 7099 1106 2401 1138 37.86 -122.22
3 352100 7.2574 52 1467 190 496 177 37.85 -122.24
4 341300 5.6431 52 1274 235 558 219 37.85 -122.25
5 342200 3.8462 52 1627 280 565 259 37.85 -122.25
6 269700 4.0368 52 919 213 413 193 37.85 -122.25
I merged Houses and California_shp using the following codes:
pts.poly <- point.in.poly(Houses,California_shp)
head(pts.poly@data)
houseValue income houseAge rooms bedrooms population households latitude longitude
1 452600 8.3252 41 880 129 322 126 37.88 -122.23
2 358500 8.3014 21 7099 1106 2401 1138 37.86 -122.22
3 352100 7.2574 52 1467 190 496 177 37.85 -122.24
4 341300 5.6431 52 1274 235 558 219 37.85 -122.25
5 342200 3.8462 52 1627 280 565 259 37.85 -122.25
6 269700 4.0368 52 919 213 413 193 37.85 -122.25
NAME
1 Alameda
2 Alameda
3 Alameda
4 Alameda
5 Alameda
6 Alameda
head(tapply(pts.poly@data$houseValue,list(pts.poly@data$NAME),mean))
Alameda Alpine Amador Butte Calaveras Colusa
208747.39 118700.00 117146.43 89611.54 107893.75 77731.25
When I want to draw a thematic map by codes:
tm_shape(California_shp)+tm_borders("Blue",lwd = 2)+tm_fill("houseValue")
I get the following error:
Error: Fill argument neither colors nor valid variable name(s)
How can I solve this error?
tm_shape(pts.poly)
. You are plottingCalifornia_shp
that doesn’t have any variable namedhouseValue
, that’s why you get that error.tm_shape(pts.poly)+tm_borders("Blue",lwd = 2)
. Unfortunately, I get the following error:Error: pts.poly consists of spatial points, so it cannot accept tm_fill/tm_borders/tm_polygons
.