2

マップをプロットし、特定のポイントにキャプションを付けることができます。

library(maps)
map("state")
text(-80.83,35.19,"Charlotte",cex=.6)

その点を中心とする円をプロットすることもできます。

symbols(-80.83,35.19,circles=2, add=TRUE)

ただし、円のサイズを制御したいと思います。特に、data.frame、matrix、または list に含まれる複数の場所の周りに半径 100 マイルの円を描きたいと考えています。

4

2 に答える 2

16

Gary の命題は平面地図によく適合していますが、地図を描くために使用される投影を考慮しないため、「maps」パッケージによって生成された地図には適用できません。これを厳密に適用すると、円の半径の単位は度であり、キロメートルやマイルではないため、楕円が描画されます (以下を参照)。しかし、緯度と経度の度数は、同じ物理的距離に対応していません。ポイントの周りに円または円に近いものを描くには、半径がマイルまたはキロメートル単位の定数距離である場合、投影に関して修正された座標を計算する必要があります。関数を取り、 http: //www.movable-type.co.uk のChris Veness の説明に合わせて適応させると 、関数は次のようになりました。

library(maps)
library(mapdata)#For the worldHires database
library(mapproj)#For the mapproject function
plotElipse <- function(x, y, r) {#Gary's function ;-)
   angles <- seq(0,2*pi,length.out=360)
   lines(r*cos(angles)+x,r*sin(angles)+y)
}
plotCircle <- function(LonDec, LatDec, Km) {#Corrected function
    #LatDec = latitude in decimal degrees of the center of the circle
    #LonDec = longitude in decimal degrees
    #Km = radius of the circle in kilometers
    ER <- 6371 #Mean Earth radius in kilometers. Change this to 3959 and you will have your function working in miles.
    AngDeg <- seq(1:360) #angles in degrees 
    Lat1Rad <- LatDec*(pi/180)#Latitude of the center of the circle in radians
    Lon1Rad <- LonDec*(pi/180)#Longitude of the center of the circle in radians
    AngRad <- AngDeg*(pi/180)#angles in radians
    Lat2Rad <-asin(sin(Lat1Rad)*cos(Km/ER)+cos(Lat1Rad)*sin(Km/ER)*cos(AngRad)) #Latitude of each point of the circle rearding to angle in radians
    Lon2Rad <- Lon1Rad+atan2(sin(AngRad)*sin(Km/ER)*cos(Lat1Rad),cos(Km/ER)-sin(Lat1Rad)*sin(Lat2Rad))#Longitude of each point of the circle rearding to angle in radians
    Lat2Deg <- Lat2Rad*(180/pi)#Latitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
    Lon2Deg <- Lon2Rad*(180/pi)#Longitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
    polygon(Lon2Deg,Lat2Deg,lty=2)
}
map("worldHires", region="belgium")#draw a map of Belgium (yes i am Belgian ;-)
bruxelles <- mapproject(4.330,50.830)#coordinates of Bruxelles
points(bruxelles,pch=20,col='blue',cex=2)#draw a blue dot for Bruxelles
plotCircle(4.330,50.830,50)#Plot a dashed circle of 50 km arround Bruxelles 
plotElipse(4.330,50.830,0.5)#Tries to plot a plain circle of 50 km arround Bruxelles, but drawn an ellipse

画像の結果

(申し訳ありませんが、私の「評判」により、画像を投稿できません;-)。編集:画像を追加しました。

これが役立つことを願っています。グレゴワール

于 2015-03-18T22:26:52.523 に答える
1

円の外観をカスタマイズする関数を作成できます。例えば:

plotCircle <- function(x, y, r) {
  angles <- seq(0,2*pi,length.out=360)
  lines(r*cos(angles)+x,r*sin(angles)+y)
}

次に、データ フレームに一連の座標がある場合:

coords <- data.frame(x = c(-1,0,1), y = c(-1, 0.5, 1))

いくつかの初期プロット(マップ、または空のプロットなど)から始めることができます

plot(1,type='n',xlim=c(-2,2),ylim=c(-2,2))

次に、座標のリストに対してプロット関数を呼び出します。

apply(coords,1,function(df) plotCircle(df[1],df[2],.3))
于 2014-04-14T23:21:41.140 に答える