質問/問題は元のquestionと非常によく似ています。小数点以下の桁数をggplotの軸ラベルで分単位の秒数に変更してください。「ggplotのフォーマット緯度と経度軸のラベル」
私はこれらの手順を実行しています。また
library(ggplot2)
library(ggmap)
#get my map
city<- get_map(location = c(lon= -54.847, lat= -22.25),
maptype = "satellite",zoom = 11,color="bw")
map<-ggmap(city,extent="normal")+
xlab("Longitude")+ ylab("Latitude")
map
、私は@Jaapが書いたものしようとしている:だから
scale_x_longitude <- function(xmin=-180, xmax=180, step=1, ...) {
xbreaks <- seq(xmin,xmax,step)
xlabels <- unlist(lapply(xbreaks, function(x) ifelse(x < 0, parse(text=paste0(x,"^o", "*W")), ifelse(x > 0, parse(text=paste0(x,"^o", "*E")),x))))
return(scale_x_continuous("Longitude", breaks = xbreaks, labels = xlabels, expand = c(0, 0), ...))
}
scale_y_latitude <- function(ymin=-90, ymax=90, step=0.5, ...) {
ybreaks <- seq(ymin,ymax,step)
ylabels <- unlist(lapply(ybreaks, function(x) ifelse(x < 0, parse(text=paste0(x,"^o", "*S")), ifelse(x > 0, parse(text=paste0(x,"^o", "*N")),x))))
return(scale_y_continuous("Latitude", breaks = ybreaks, labels = ylabels, expand = c(0, 0), ...))
}
:
map+
scale_x_longitude(-55.0,-54.7,4)+
scale_y_latitude(-22.4,-22.1,4)
2番目のマップでは、2つの座標だけが描画され、間違った形式です。 私は次のように書かれたこれらのコルディネイトが必要です:
55ºW、54ºW54 '、54ºW48'、54ºW42 '; 22ºS24 '、22ºS18'、22ºS12 '、22ºS06'
誰でも手伝ってもらえますか?
アップデート(16/08/2017) @Rafael Cunha(更新ありがとうございます)のアップデートコードです。 分記号を追加する方法がまだありません。しかし、以前よりもうまくいっています。私は度分秒に小数度を変換するためにGEOmap
パッケージから機能dms
を使用
scale_x_longitude <- function(xmin=-180, xmax=180, step=1, ...) {
xbreaks <- seq(xmin,xmax,step)
xlabels <- unlist(
lapply(xbreaks, function(x){
ifelse(x < 0, parse(text=paste0(paste0(abs(dms(x)$d),"^{o}*"),
paste0(abs(dms(x)$m)), "*W")),
ifelse(x > 0, parse(text=paste0(paste0(abs(dms(x)$d),"^{o}*"),
paste0(abs(dms(x)$m)),"*E")),
abs(dms(x))))}))
return(scale_x_continuous("Longitude", breaks = xbreaks, labels = xlabels, expand = c(0, 0), ...))
}
scale_y_latitude <- function(ymin=-90, ymax=90, step=0.5, ...) {
ybreaks <- seq(ymin,ymax,step)
ylabels <- unlist(
lapply(ybreaks, function(x){
ifelse(x < 0, parse(text=paste0(paste0(abs(dms(x)$d),"^{o}*"),
paste0(abs(dms(x)$m)),"*S"),
ifelse(x > 0, parse(text=paste0(paste0(abs(dms(x)$d),"^{o}*"),
paste0(abs(dms(x)$m)),"*N")),
abs(dms(x))))}))
return(scale_y_continuous("Latitude", breaks = ybreaks, labels = ylabels, expand = c(0, 0), ...))
}
map+
scale_x_longitude(-55.0,-54.7,.1)+
scale_y_latitude(-22.4,-22.1,.1)
ありがとう@ C.Aldridge!それは働いている;) –