我有基於位置的響應時間數據,每個州。我想能夠創建熱圖的地圖類型:如何在ggplot中創建基於地圖的熱圖
有我的DF:
structure(list(DATE_TIME = structure(c(1369419660, 1369419720,
1369419720, 1369419780, 1369419780, 1369419840, 1369419840, 1369419900,
1369419960, 1369419960, 1369419960, 1369420020, 1369420020, 1369420020,
1369420020, 1369420080, 1369420080, 1369420080, 1369420080, 1369420140,
1369420140, 1369420140, 1369420140, 1369420200, 1369420200, 1369420260,
1369420260, 1369420260, 1369420260, 1369420260), class = c("POSIXct",
"POSIXt"), tzone = ""), SITE = c("Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts", "Logon to My Accounts", "Logon to My Accounts",
"Logon to My Accounts"), RESPONSE_TIME = c(7.069, 7.056, 11.535,
7.33, 9.566, 5.21, 6.483, 6.652, 8.222, 9.368, 10.055, 6.301,
6.33, 7.802, 10.132, 6.241, 6.997, 7.499, 7.823, 6.173, 6.912,
7.979, 10.128, 7.072, 7.65, 6.048, 7.681, 8.08, 8.272, 9.583),
AVAIL_PERCENT = c(100L, 100L, 100L, 100L, 100L, 100L, 100L,
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L,
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L,
100L, 100L, 100L), AGENT = c(45869L, 45540L, 45672L, 45036L,
45421L, 42627L, 44981L, 42432L, 45869L, 45693L, 42108L, 40522L,
40521L, 45540L, 45672L, 40517L, 45036L, 45421L, 40511L, 42627L,
44981L, 40370L, 40369L, 40368L, 42432L, 40282L, 45693L, 42108L,
40296L, 45869L), LOCATION = c("seattle", "hartford", "houston",
"san diego", "montreal", "new york", "philadelphia", "chicago",
"seattle", "dallas", "pittsburgh", "miami", "denver", "hartford",
"houston", "atlanta", "san diego", "montreal", "milwaukee",
"new york", "philadelphia", "vancouver", "toronto", "calgary",
"chicago", "san jose", "dallas", "pittsburgh", "mexico city",
"seattle")), .Names = c("DATE_TIME", "SITE", "RESPONSE_TIME",
"AVAIL_PERCENT", "AGENT", "LOCATION"), row.names = c(NA, 30L), class = "data.frame")
我嘗試這樣做:
require(maps)
require(ggplot2)
ggplot(df, aes(map_id = LOCATION)) + geom_map(aes(fill = RESPONSE_TIME), map = states_map) + expand_limits(x = states_map$long, y = states_map$lat)
任何想法,我做錯了什麼?
'states_map'對象來自哪裏? – harkmug
@rmk我試圖做這個states_map <-map_data(「狀態」) – user1471980
@rmk我不需要子區域。 – user1471980