Saya mencoba membuat plot peta, tetapi saya tidak tahu mengapa hal berikut ini tidak berhasil:
Berikut adalah contoh minimalnya
testdf <- structure(list(x = c(48.97, 44.22, 44.99, 48.87, 43.82, 43.16, 38.96, 38.49, 44.98, 43.9), y = c(-119.7, -113.7, -109.3, -120.6, -109.6, -121.2, -114.2, -118.9, -109.7, -114.1), z = c(0.001216, 0.001631, 0.001801, 0.002081, 0.002158, 0.002265, 0.002298, 0.002334, 0.002349, 0.00249)), .Names = c("x", "y", "z"), row.names = c(NA, 10L), class = "data.frame")
Ini berfungsi untuk 1-8 baris:
ggplot(data = testdf[1,], aes(x,y,fill = z)) + geom_tile()
ggplot(data = testdf[1:8,], aes(x,y,fill = z)) + geom_tile()
Tapi tidak untuk 9 baris:
ggplot(data = testdf[1:9,], aes(x,y,fill = z)) + geom_tile()
Pada akhirnya, saya mencari cara untuk memplot data pada grid non-reguler. Saya tidak perlu menggunakan geom_tile, tetapi interpolasi pengisian ruang apa pun pada titik-titik tersebut bisa dilakukan.
Kumpulan data lengkap tersedia di intisari
testdf
di atas adalah sebagian kecil dari kumpulan data lengkap, raster resolusi tinggi AS (>7500 baris)
require(RCurl) # requires libcurl; sudo apt-get install libcurl4-openssl-dev
tmp <- getURL("https://gist.github.com/raw/4635980/f657dcdfab7b951c7b8b921b3a109c7df1697eb8/test.csv")
testdf <- read.csv(textConnection(x))
Apa yang saya coba:
menggunakan geom_point berfungsi, tetapi tidak memberikan efek yang diinginkan:
ggplot(data = testdf, aes(x,y,color=z)) + geom_point()
jika saya mengonversi x atau y ke vektor 1:10, plotnya berfungsi seperti yang diharapkan:
newdf <- transform(testdf, y =1:10) ggplot(data = newdf[1:9,], aes(x,y,fill = z)) + geom_tile() newdf <- transform(testdf, x =1:10) ggplot(data = newdf[1:9,], aes(x,y,fill = z)) + geom_tile()
sessionInfo()R version 2.15.2 (2012-10-26) Platform: x86_64-pc-linux-gnu (64-bit)
> attached base packages: [1] stats graphics grDevices utils
> datasets methods base
> other attached packages: [1] reshape2_1.2.2 maps_2.3-0
> betymaps_1.0 ggmap_2.2 ggplot2_0.9.3
> loaded via a namespace (and not attached): [1] colorspace_1.2-0
> dichromat_1.2-4 digest_0.6.1 grid_2.15.2
> gtable_0.1.2 labeling_0.1 [7] MASS_7.3-23
> munsell_0.4 plyr_1.8 png_0.1-4
> proto_0.3-10 RColorBrewer_1.0-5 [13] RgoogleMaps_1.2.0.2
> rjson_0.2.12 scales_0.2.3 stringr_0.6.2
> tools_2.15.2
geom_raster
ataugeom_tile
. Lihat jawaban saya untuk detail dan solusi yang menggunakangeom_raster
. - person Simon O'Hanlon   schedule 12.03.2013