我正在尝试在地图上绘制垂直条形图。我在网上浏览了一些例子,但不知何故无法做到。
我的数据目前是这种格式:
University| Count | Category | lat | long
这是我尝试执行的代码:
library(ggplot2)
library(ggmap)
library(ggsubplot)
df1 <- data.frame(
University = c(rep("University1", 4), rep("University2", 4), rep("University3", 4),
rep("University4", 4)),
Count = sample(1:10, 16, replace = T),
Category = rep(c("A", "B", "C", "D")),
lat = c(rep(10.902469, 4), rep(17.921959, 4), rep(18.606910, 4), rep(13.202366, 4)),
long = c(rep(76.90020, 4), rep(83.42510, 4), rep(73.87501, 4), rep(77.62340, 4))
)
india <- get_map("India", zoom = 5)
p <- ggmap(india)
p + geom_subplot(data = df1, mapping=aes(x = long, y = lat, group = University,
subplot= geom_bar(aes(x = Category, y = Count, color = Category, stat = "identity"))))
当我运行上面的代码时,我收到以下错误:
Error in get(x, envir = this, inherits = inh)(this, ...) :
could not find function "%:::%"