如何在geom_path上放置geom_bar

时间:2018-05-11 17:50:00

标签: r ggplot2

我想在使用ggmaps绘制的路径上的某些位置添加条形图。因此,在特定的纬度/经度处geom_bar

# first append the lat/lng's provided below to PlantGrowth
df <- cbind(PlantGrowth[c(1:25),], Lat, Lng)

library(maps)
library(mapdata)
library(ggmap)

boundingBox <- df[c("lat", "lng")]

sbbox <- make_bbox(lon = boundingBox$lng, lat = boundingBox$lat, f = .4)
sq_map <- get_map(location = sbbox, maptype = "terrain", source = "google")

ggmap(sq_map) + 
  geom_path(data = df, mapping = aes(x = lng, y = lat), size = 2)

现在的目标是在这里添加geom_bar(),如:

ggmap(sq_map) + 
      geom_path(data = df, mapping = aes(x = lng, y = lat), size = 2) + 
      geom_bar(aes(x = group, y = weight / sum(weight)), stat = "identity"))

但是如何添加它,以及如何将它放在路径上的特定位置(假设数据帧的第20行)

示例Lat / Lng:

"","lat","lng"
"1",40.4922385,-80.0100821
"2",40.4926913,-80.0102002
"3",40.4874285,-80.00902
"4",40.4884851,-80.009248
"5",40.493034,-80.0103235
"6",40.4935725,-80.0106776
"7",40.4932829,-80.0104684
"8",40.490268,-80.0096476
"9",40.4948616,-80.01248
"10",40.4946944,-80.0120938
"11",40.4945108,-80.0117398
"12",40.4939968,-80.0110746
"13",40.494266,-80.011375
"14",40.4937928,-80.0108654
"15",40.46878,-80.0021015
"16",40.4797374,-80.0072444
"17",40.4780604,-80.0074321
"18",40.4829649,-80.0074858
"19",40.4814267,-80.0072015
"20",40.4807942,-80.0071693
"21",40.4825079,-80.0073731
"22",40.4774483,-80.0074858
"23",40.4820305,-80.0072819
"24",40.4802801,-80.0071907
"25",40.4698826,-80.0029207

0 个答案:

没有答案