【发布时间】:2015-03-18 09:06:20
【问题描述】:
我的普林斯顿不同地点的流量数据框。
# dput(count)
structure(list(intersection = structure(c(11L, 9L, 10L, 12L,
6L, 3L, 7L, 2L, 4L, 1L, 5L, 8L), .Label = c("CherryHillat206",
"ElmatRidgeRd", "FacultyatHarrison", "HarrisonatLake", "HarrisonbetwHamilton",
"MerceratLoversLane", "ProvinceLineatMercer", "RiverRdat27",
"Rt 27 Bank", "Rt. 27 River Rd", "US206 Cambelton", "US206Princeton Ave."
), class = "factor"), traffic = c(19352, 18697, 12493, 21554,
10871, 13310, 7283, 11408, 12055, 6415, 14100, 5739), lat = c(40.3475418,
40.3487282, 40.3711205, 40.3909988, 40.3403702, 40.3434601, 40.343689,
40.3440514, 40.3454819, 40.3627014, 40.3658734, 40.3738098),
lon = c(-74.6711197, -74.6630707, -74.62323, -74.6541214,
-74.6720123, -74.647049, -74.7051392, -74.7334671, -74.6390533,
-74.6648483, -74.6596518, -74.6207962), class = structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("primary",
"secondary"), class = "factor")), .Names = c("intersection",
"traffic", "lat", "lon", "class"), row.names = c(NA, -12L), class = "data.frame")
library(ggplot2)
library(ggmap)
map <- get_map(location = 'princeton', zoom = 13, maptype = "road")
ggmap(map) +
geom_point(data = count, aes(x = lon, y = lat)) +
annotate("text", x = -74.7, y = 40.4, label = "TEST anno")
早先的问题1 conflict with annotate in other package 没用2 solution to create another data frame。
编辑每条评论——我得到的错误信息:
Error: 'x' and 'units' must have length > 0
这是显示坐标轴边界的图。
【问题讨论】:
-
您是否收到此错误:
Error: ggplot2 doesn't know how to deal with data of class function -
@rmuc8: 不,我得到错误:'x' and 'units' must have length > 0
-
使用您的数据 c&p,我收到上面发布的错误。但是,您可能希望在帖子中包含错误消息。
-
我认为你的数据名称是
Error: ggplot2 doesn't know how to deal with data of class function的原因。count是 plyr/dplyr 中的一个函数。一旦我将数据的名称更改为 mydf,我就有了Error: 'x' and 'units' must have length > 0。 -
如果你有一个较小的缩放值,我想你会看到文字。
map2 <- get_map(location = 'princeton', zoom = 12, maptype = "road")。至少,我看到了你想要的文字。鉴于我仍然认为map中不存在您尝试注释的点。