[問題] 如何在地圖上加上標籤

看板R_Language作者 (apoooo)時間8年前 (2017/04/20 22:11), 8年前編輯推噓0(004)
留言4則, 1人參與, 最新討論串1/1
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 請把以下不需要的部份刪除 入門(寫過其他程式,只是對語法不熟悉) [問題敘述]: 我已經畫出地圖,但若只想標示出特定城市,該如何設定? [程式範例]: library(maptools) library(ggmap) library(ggplot2) tw.map <- readShapeSpatial("D:\\Master Degree\\Thesis\\R_code\\Map\\COUNTY_MOI_1051214.shp") ggplot(tw.map,aes(x=long,y=lat,group=group)) + geom_polygon(fill="white",colour="grey") + coord_map("polyconic") 這邊是畫好的地圖 https://imgur.com/a/XMEB3 c1 = gCentroid(countytaiwan,byid=TRUE) points(c1) text(c1@coords, levels(tw.map@data$COUNTYENG)) 用這個方法上標籤上不上去,且這個CODE會標示全部城市,請問若我只要 台北市、台中市、高雄市的畫要怎麼篩選出來呢? 有找到geom_text()但一直試不出來 [環境敘述]: 3.3.3 [關鍵字]: ggplot2、地圖 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.134.18.163 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1492697460.A.8C2.html

04/20 22:27, , 1F
你不能用text, gg系列的繪圖API與原生的API不同
04/20 22:27, 1F

04/20 22:28, , 2F
geom_text(aes(x = ..., y = ..., label = ...),data=df)
04/20 22:28, 2F

04/20 22:29, , 3F
你要用`+`的把圖層疊上去
04/20 22:29, 3F
我有試過,嘗試先標一個,放geom_text(aes(x=120,y=25,label="Taipei"))也不行,dat a我有放過也失敗TAT ※ 編輯: mvp24213 (111.83.63.61), 04/20/2017 22:48:11

04/21 16:11, , 4F
data怎麼放,怎麼失敗,麻煩放上code,否則大家沒辦法幫
04/21 16:11, 4F
文章代碼(AID): #1O-C5qZ2 (R_Language)
文章代碼(AID): #1O-C5qZ2 (R_Language)