damned-to-suffer
damned-to-suffer

Reputation: 103

geom_points in ggmap not filling by variable

I'm using the Taiwan housing data found on UCI ML repository.

I'm trying to plot the houses on a map using ggplot, and fill the points with the house_price_unit_area. However, when I use fill = house_price_unit_area in the aesthetic call, it doesn't fill the points based on price, but rather it leaves them black.

Any suggestions on how to fix this? Code included below, as well as a screenshot of what is produced.

enter image description here

library(ggplot)
library(ggmap)
library(readxl)

df <- read_xlsx("data/real_estate.xlsx")
df$No = NULL
colnames(df)= c("trans_date",
                "house_age",
                "distance_to_nearest_mrt",
                "number_of_conv_store",
                "lat",
                "long",
                "house_price_unit_area",
                "id")

world <- map_data(database = "world", regions = "Taiwan")

ggmap(get_stamenmap(bbox = c(left = 121.4, right = 121.64, bottom=24.9,top=25.1),location = "Taiwan"))+
  geom_point(data =df, mapping = aes(x=long,y=lat, fill = house_price_unit_area))+
  scale_fill_viridis_b()

Upvotes: 0

Views: 19

Answers (1)

Claudio Paladini
Claudio Paladini

Reputation: 1028

I switch the fill argument for col and got this:

library(ggplot)
library(ggmap)
library(readxl)

df <- read_xlsx("Real estate valuation data set.xlsx")
df$No = NULL
colnames(df)= c("trans_date",
                "house_age",
                "distance_to_nearest_mrt",
                "number_of_conv_store",
                "lat",
                "long",
                "house_price_unit_area",
                "id")

world <- map_data(database = "world", regions = "Taiwan")

ggmap(get_stamenmap(bbox = c(left = 121.4, right = 121.64, bottom=24.9,top=25.1),location = "Taiwan"))+
  geom_point(data =df, mapping = aes(x=long,y=lat, col = house_price_unit_area))+
  scale_fill_viridis_b()

output:

enter image description here

Upvotes: 1

Related Questions