1

Rで素敵な空間マップを作成しようとしています。データを確認したい場合に備えて、データをアップロードする方法を理解しようとしていますが、わかりません(申し訳ありませんが、新しいです)ユーザーとは、これらすべてのものを探すことを意味します)。

私の状況はどうですか。米国全体のシェープファイルがあり、必要なのは一部の状態だけです。グリッドをプロットするときにグリッドを選択できます(プロットセクションのコードからわかるように)。

また、緯度、経度、および歩留まりを持つ歩留まりデータ(ポイント)もいくつかあります。「すべてのステーション」、「0.5」、「1.0」、「2.0」と呼ばれる4つの異なる歩留まりデータがあります。

これらの4つの収量データを空間マップにプロットして、4つの異なる空間マップを作成しようとしています。どちらが行われます。

私はあちこちでstackoverflowを読んでこれを行いましたが、それを行うために少しずつ使用しましたが、私がどれほど速く進むことができるかに驚いた前にそれをしたことはありませんでした(StackOverflowの人々に感謝します!!!)。

誰かが私のコードが正しいかどうかを理解するのを手伝ってもらえますか?

また、4つのマップの凡例をより規則的な縮尺にするにはどうすればよいですか?たとえば、4つのマップのそれぞれに500間隔で4000から9000まで。私が行ったことは、マップと凡例のカラースケールを生成するために使用する別のテキストファイル( "Yield for Legend.txt")を作成することです。あれは正しいですか?

繰り返しますが、あなたの批評家は大歓迎です!

ありがとう、デビッド

    rm(list=ls())
    setwd("C:\\Users\\.....\\Shape File")
    library(spatstat)
    library(rgdal)
    library(shapefiles)
    library(maptools)
    library(RColorBrewer)
    library(classInt)


    # read in shapefiles

    counties.rg <- readOGR("C:\\Users\\......\\Shape File", "tl_2011_us_county")


    Yields <- read.table("Yield.txt", skip=1, header = F)

    Yield.g <- as.ppp(Yields, owin( c(-89, -76), c(25, 37)))

    ## Reading Data for Legend and colouring breaks

     Y.LE <- read.table("Yield for Legend.txt", header=F)
     Y.L.I <- classIntervals(Y.LE$V1, n=9, style = "quantile")
     Y.L.I <- Y.L.I$brks

    #select color palette and the number colors (levels of income) to represent on the map
    #colors <- brewer.pal(9, "RdYlGn")
    colors <- brewer.pal(9, "Greys")

    ################################################
    ### Generating MAPS ############################
    ################################################

    #set breaks for the 9 colors
      #par(mfrow=c(2,2))

     pdf("13 August Spatial Maps.pdf") 
    # All Points 

    brks.all <-classIntervals(Yields$V3, n=9, style = "quantile")
    brks.all <- brks.all$brks

    plot(counties.rg, axes=TRUE, border="grey", xlim = c(-82, -80),
        ylim = c(24, 37))
    points(Yield.g, cex= 1.1, bg=colors[findInterval(Yields$V3, Y.L.I,all.inside=TRUE)], pch=21)

    #add a title
    title(paste ("Rainfed Yield (kg/ha)All Stations"))

    #add a legend
    legend("bottomright", legend=leglabs(round(Y.L.I)), fill=colors, bty="n", cex=0.7 ) #,x.intersp = .5, y.intersp = .5)



    # 0.5 Grid  
    brks.05 <-classIntervals(Yields$V4, n=9, style = "quantile")
    brks.05 <- brks.05$brks

    plot(counties.rg, axes=TRUE, border="grey", xlim = c(-82, -80),
        ylim = c(24, 37))
    points(Yield.g, cex= 1.1, bg=colors[findInterval(Yields$V4, Y.L.I,all.inside=TRUE)], pch=21)
    #abline(v=GF$V1, col="grey40")
    #abline(h=GF$V2, col="grey10", lty="dotted")
    #backup
    #points(Yield.g, cex= Yields$V4/9000, col=colors[findInterval(Yields$V4, brks.05,all.inside=TRUE)], pch=19)

    #add a title
    title(paste ("Rainfed Yield (kg/ha)0.5"))

    #add a legend
    legend("bottomright", legend=leglabs(round(Y.L.I)), fill=colors, bty="n", cex=0.7 ) #,x.intersp = .5, y.intersp = .5)


    # 1.0 Grid
    brks.1 <-classIntervals(Yields$V5, n=9, style = "quantile")
    brks.1 <- brks.1$brks

    plot(counties.rg, axes=TRUE, border="grey", xlim = c(-82, -80),
        ylim = c(24, 37))
    points(Yield.g, cex= 1.1, bg=colors[findInterval(Yields$V5, Y.L.I,all.inside=TRUE)], pch=21)
    #abline(v=GO$V1, col="grey40")
    #abline(h=GO$V2, col="grey10", lty="dotted")
    #add a title
    title(paste ("Rainfed Yield (kg/ha)1.0"))

    #add a legend
    legend("bottomright", legend=leglabs(round(Y.L.I)), fill=colors, bty="n", cex=0.7 ) #,x.intersp = .5, y.intersp = .5)


    # 2.0 Grid

    brks.2 <-classIntervals(Yields$V6, n=9, style = "quantile")
    brks.2 <- brks.2$brks

    plot(counties.rg, axes=TRUE, border="grey", xlim = c(-82, -80),
        ylim = c(24, 37))
    points(Yield.g, cex= 1.1, bg=colors[findInterval(Yields$V6, Y.L.I,all.inside=TRUE)], pch=21)
    #abline(v=GG$V1, col="grey40")
    #abline(h=GG$V2, col="grey10", lty="dotted") 
    #add a title
    title(paste ("Rainfed Yield (kg/ha)2.0"))

    #add a legend
    legend("bottomright", legend=leglabs(round(Y.L.I)), fill=colors, bty="n", cex=0.7 ) #,x.intersp = .5, y.intersp = .5)
dev.off()
4

1 に答える 1

2

ブレークの設定と凡例の一致に関する特定のクエリに応じて、かなり簡単な修正があります。

classInterval関数をstyle="quantile"とともに使用して、ブレークを定義します。マップに「4つのマップのそれぞれに500間隔で4000から9000まで」を表示させたい場合は、style="fixed"を使用してみませんか。

brks.all <-classIntervals(Yields$V3, n=10, style = "fixed",
  fixedBreaks=seq(from=4000, to=9000, by=500)
brks.all <- brks.all$brks 

4kから9kx500の場合、私のカウントでは10の間隔が作成され、9つのカラーグラデーションではきれいなマップにはならないことがよくあります。

あるいは、classInt内のdataPrecision変数は、必要なものに近いラベルとブレークを取得するのに役立つ場合がありますが、それでも分位数に基づいています(マップ全体で均一でない場合)

于 2012-08-13T19:47:45.593 に答える