R語言_樣點分布圖

1) 經(jīng)緯度轉(zhuǎn)換

# DMS to DD

# method 1 
> library(sp)
Warning message:
程輯包‘sp’是用R版本4.0.5 來建造的 
> as.numeric(char2dms("48°26'5\"N", chd = "°", chm = "'", chs='"'))
[1] 48.43472


# method 2 
# load test data
> head(test)
  site       lat        lon
1    1  18°21'5"   43°59'5"
2    2  42°26'6"  113°30'6"
3    3  16°26'7"   97°34'7"
4    4  55°26'8"   99°13'8"
5    5  13°26'9"   20°42'9"
6    6 58°26'10" 109°23'10"
#  extracting values from degree, minute, second with regular expression
 > test1 = test %>%
  mutate(Dlat = str_extract(test$lat, "(?<=^)(.*)(?=°)"),
         Mlat = str_extract(test$lat, "(?<=°)(.*)(?=')"),
         Slat = str_extract(test$lat, "(?<=')(.*)(?=\")"),
         Dlon = str_extract(test$lon, "(?<=^)(.*)(?=°)"),
         Mlon = str_extract(test$lon, "(?<=°)(.*)(?=')"),
         Slon = str_extract(test$lon, "(?<=')(.*)(?=\")")) %>% 
  select(site, Dlat, Mlat, Slat, Dlon, Mlon, Slon) %>%
  apply(., 2, as.numeric)  %>%
  as.data.frame() %>%
  mutate(DDlat = Dlat + Mlat/60 + Slat/3600, 
         DDlon = Dlon + Mlon/60 + Slon/3600)

> head(test1)
  site Dlat Mlat Slat Dlon Mlon Slon    DDlat     DDlon
1    1   18   21    5   43   59    5 18.35139  43.98472
2    2   42   26    6  113   30    6 42.43500 113.50167
3    3   16   26    7   97   34    7 16.43528  97.56861
4    4   55   26    8   99   13    8 55.43556  99.21889
5    5   13   26    9   20   42    9 13.43583  20.70250
6    6   58   26   10  109   23   10 58.43611 109.38611

2)樣點分布圖

ArcGIS也可以做,依然參照圖層概念著拭,在底圖上添加樣點纱扭,設置經(jīng)緯度網(wǎng)格等等。R中做法如下:

#  load .shp files 
#  the map of china
> china <- read_sf("E:/GIS/四百萬數(shù)據(jù)/省界(線).shp")

# method 1:tmap包
> library(sf)
> library(tmap)
> library(tmaptools)
> library(sp)
> library(readxl)
> library(grid)

# load information of site locations 
> head(sites)
   newname longitude latitude
1 Leo_1_R1  95.25550 31.54113
2 Leo_1_R2  95.25550 31.54113
3 Leo_1_R3  95.25550 31.54113
4 Leo_2_R1  92.93162 31.84779
5 Leo_2_R2  92.93162 31.84779
6 Leo_2_R3  92.93162 31.84779

# set spatial coordinates to create a Spatial object
coordinates(sites) <- ~longitude+latitude 
proj4string(sites) <- CRS("+proj=longlat +datum=WGS84")

# plotting
> map1 <- 
  tm_shape(china,ylim=c(25,36), xlim=c(75,100))+
  tm_lines(col = "darkgrey", lwd = 1)+
  tm_layout(scale = 0.6,
            legend.position = c("left","bottom"),
            inner.margins = c(0.12,0.03,0.08,0.03))+
  tm_shape(sites)+
  tm_symbols(
    size = 0.7,
    shape = 16,
    col = "royalblue3")+
  tm_graticules(x= c(75,85,95,100),
                y= c(25,28,31,34,37),
                lwd = 0.5, col="lightgrey",
                labels.size = 1.2)+
  tm_compass(type = "arrow",
             position = c("left","top"),
             size = 5)+
  tm_scale_bar(position = c("left","bottom"),
               size = 1.2); map1


# method2: geom_sf()
# load information of climate stations in Tibet
> head(MAPsite)
# A tibble: 6 x 2
  longitude latitude
      <dbl>    <dbl>
1      80.0     32.3
2      84.2     32.1
3      92.0     31.3
4      81.2     30.2
5      91.1     30.3
6      87.4     29.0

# convert foreign object to an sf object
> MAPsite  = MAPsite  %>%
  st_as_sf(coords = c("longitude", "latitude")) %>%
  st_set_crs(st_crs(china))

# plotting
> ggplot() +
  geom_sf(data = china)+
  geom_sf(data = MAPsite, col = "red")+
  theme_bw()

Method 1
Method 2
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末儡遮,一起剝皮案震驚了整個濱河市乳蛾,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖肃叶,帶你破解...
    沈念sama閱讀 216,997評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蹂随,死亡現(xiàn)場離奇詭異,居然都是意外死亡因惭,警方通過查閱死者的電腦和手機岳锁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,603評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蹦魔,“玉大人激率,你說我怎么就攤上這事∥鹁觯” “怎么了乒躺?”我有些...
    開封第一講書人閱讀 163,359評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長剥险。 經(jīng)常有香客問我聪蘸,道長,這世上最難降的妖魔是什么表制? 我笑而不...
    開封第一講書人閱讀 58,309評論 1 292
  • 正文 為了忘掉前任健爬,我火速辦了婚禮,結(jié)果婚禮上么介,老公的妹妹穿的比我還像新娘娜遵。我一直安慰自己,他們只是感情好壤短,可當我...
    茶點故事閱讀 67,346評論 6 390
  • 文/花漫 我一把揭開白布设拟。 她就那樣靜靜地躺著,像睡著了一般久脯。 火紅的嫁衣襯著肌膚如雪纳胧。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,258評論 1 300
  • 那天帘撰,我揣著相機與錄音跑慕,去河邊找鬼。 笑死摧找,一個胖子當著我的面吹牛核行,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蹬耘,決...
    沈念sama閱讀 40,122評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼芝雪,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了综苔?” 一聲冷哼從身側(cè)響起惩系,我...
    開封第一講書人閱讀 38,970評論 0 275
  • 序言:老撾萬榮一對情侶失蹤位岔,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蛆挫,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赃承,經(jīng)...
    沈念sama閱讀 45,403評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,596評論 3 334
  • 正文 我和宋清朗相戀三年悴侵,在試婚紗的時候發(fā)現(xiàn)自己被綠了瞧剖。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,769評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡可免,死狀恐怖抓于,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情浇借,我是刑警寧澤捉撮,帶...
    沈念sama閱讀 35,464評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站妇垢,受9級特大地震影響巾遭,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜闯估,卻給世界環(huán)境...
    茶點故事閱讀 41,075評論 3 327
  • 文/蒙蒙 一灼舍、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧涨薪,春花似錦骑素、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,705評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至侠姑,卻和暖如春创橄,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背莽红。 一陣腳步聲響...
    開封第一講書人閱讀 32,848評論 1 269
  • 我被黑心中介騙來泰國打工筐摘, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人船老。 一個月前我還...
    沈念sama閱讀 47,831評論 2 370
  • 正文 我出身青樓怠褐,卻偏偏與公主長得像狰腌,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子掸掏,可洞房花燭夜當晚...
    茶點故事閱讀 44,678評論 2 354

推薦閱讀更多精彩內(nèi)容