[R-sig-Geo] R-sig-Geo Digest, Vol 224, Issue 2

Michael Marsh @w@mp @end|ng |rom b|@rg@net
Wed Apr 6 18:24:31 CEST 2022


Those dates sound suitable to me. There should be some chicks popping up!

mike

On 4/6/2022 3:00 AM, r-sig-geo-request using r-project.org wrote:
> Send R-sig-Geo mailing list submissions to
> 	r-sig-geo using r-project.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> or, via email, send a message with subject or body 'help' to
> 	r-sig-geo-request using r-project.org
>
> You can reach the person managing the list at
> 	r-sig-geo-owner using r-project.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of R-sig-Geo digest..."
>
>
> Today's Topics:
>
>     1. Re: Contour plot (Micha Silver)
>     2. Re: Contour plot (sownal chand)
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 5 Apr 2022 15:39:39 +0300
> From: Micha Silver <tsvibar using gmail.com>
> To: sownal chand <sownalchandfms using gmail.com>, r-sig-geo using r-project.org
> Subject: Re: [R-sig-Geo] Contour plot
> Message-ID: <1132483a-ff17-4c1f-a33d-9ab7b0a56119 using gmail.com>
> Content-Type: text/plain; charset="us-ascii"
>
> An HTML attachment was scrubbed...
> URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20220405/c6c465ca/attachment-0001.html>
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 6 Apr 2022 03:45:00 +1200
> From: sownal chand <sownalchandfms using gmail.com>
> To: Micha Silver <tsvibar using gmail.com>
> Cc: r-sig-geo using r-project.org
> Subject: Re: [R-sig-Geo] Contour plot
> Message-ID:
> 	<CAH5tCz02ij4V6i-8eNn1t1=F0hH6gvAhRCnr6hJP+p3jnnn39Q using mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Thanks Micha,
>
> I would also try out your suggestion on interpolation of data.
> Kind regards
> Sownal
>
> On Wed, Apr 6, 2022, 00:39 Micha Silver <tsvibar using gmail.com> wrote:
>
>> Hi:
>>
>> I would point to two issues with your code. First, we should be switching
>> totally to sf. You have some spatial vectors as sf classes and some as sp.
>> This should be avoided today.
>>
>>
>> Here's my version for plotting
>>
>>
>> library(ggplot2)
>> library(sf)
>> library(rnaturalearth)
>>
>> #Draft map of Fiji
>> world <- ne_countries(returnclass = "sf")
>>
>> Fiji <- ne_countries(country="Fiji", returnclass="sf")
>> data.Fdf <- read.csv("DataR.csv")
>> # Get rid of that last summary row with no coordinates!
>> data.Fdf <- data.Fdf[complete.cases(data.Fdf),]
>> data.sf <- st_as_sf(data.Fdf, coords=c("long", "lat"), crs="EPSG:4326")
>>
>> # map of Fiji Islands
>> Fiji.plot <- ggplot() +
>>    geom_sf(data=world) +
>>    geom_sf(data=Fiji) +
>>    geom_sf(data=data.sf, aes(color=Year.1965)) +
>>    coord_sf(crs = 3832, # https://epsg.io/3832
>>      xlim = c(2984265.06, 3539584.72), # limits are taken from projected
>> bounds
>>      ylim = c(-2224162.41, -1811688.88)  # of EPSG:3832
>>    ) +
>>    theme_bw()
>>
>> #Plot map of Fiji
>> Fiji.plot
>>
>>
>> But more to your question: filled.contour() is not a ggplot2 function, so
>> you cannot include it in a string of ggplot elements. filled.contour()
>> takes three main variables: a sequence of 'x' and 'y' values for the grid
>> on which to plot the contours, and a matrix 'z' of values from which
>> contours are derived. You are working with a (very) small set of *point*
>> data. No matrix of values.... Typically the 'z' matrix would be created by
>> interpolating between the points to get a continuous raster, then use that
>> for the 'z' parameter to filled.contour().
>>
>>
>> Given that you are covering an area of several 100 km, with only 13 data
>> points (and some are almost exactly overlapping), and much of the area is
>> ocean, with no measurements and probably totally different precipitation
>> behavior, I don't see any clear way to get a reliable precipitation
>> distribution, so no isohyetal contour lines.
>> Sorry :-(
>>
>>
>> To continue with this, I would first deal with only the main island of
>> Fiji, then do a kriging interpolation of annual rainfall, year by year, and
>> from those interpolated rasters, you can derive contours. You would use the
>> `contour` function from `terra` package for this.
>>
>>
>>
>>
>>
>>
>> On 05/04/2022 11:10, sownal chand wrote:
>>
>>
>>
>>
>> Hello sir/madam,
>>
>> I have been writing codes using R and was trying to overlay contour lines
>> on the map using the data set provided in the attachment. The code which I
>> am working on is attached below. The problem is the overlay of the contours
>> is not showing in the final map. If someone can assist in correcting the
>> codes would be really appreciated .
>>
>>   # Packages
>> #if (!require("rspatial")) remotes::install_github('rspatial/rspatial')
>> library(rspatial)
>> library(sp)
>> library(rgdal)
>> library(rgoes)
>> library(raster)
>> library(ggplot2)
>>
>> # Fiji geo data
>> # download
>> #Draft map of Fiji
>> world <- rnaturalearth::ne_countries(scale = "Large", returnclass = "sf")
>>
>> # map of Fiji Islands
>> Fiji <- ggplot(data=world) +
>>    geom_sf() +
>>    coord_sf(
>>      crs = 3832, # https://epsg.io/3832
>>      xlim = c(2984265.06, 3539584.72), # limits are taken from projected
>> bounds
>>      ylim = c(-2224162.41, -1811688.88)  # of EPSG:3832
>>    )+ theme_bw()
>>
>> #Plot map of Fiji
>> Fiji
>>
>> #read csv data from excel file for contoure analysis
>> data.Fdf <- read.csv("C://Users/Sownal/Documents/data.csv")
>> View(data.Fdf)
>> class(data.Fdf)
>>
>> #remove NA values in the spatial Data Frame
>> data.dfclean <- na.omit(data.Fdf)
>> data.dfclean
>>
>> data.dfclean$long <- as.numeric(data$Longitude)
>> data.dfclean$lat <- as.numeric(data$Latitude)
>>
>> # convert data to spatial data fame for spatial analysis and raster
>> analysis
>> data.FSP <- SpatialPointsDataFrame(data= data.dfclean, coords =
>> data.dfclean$lat, data.dfclean$long)
>> data.FSP
>> #select one years data and overlay contours on the Map of Fiji
>>
>> Fiji <- ggplot(data=world) +
>>    geom_sf() +
>>    coord_sf(
>>      crs = 3832, # https://epsg.io/3832
>>      xlim = c(2984265.06, 3539584.72), # limits are taken from projected
>> bounds
>>      ylim = c(-2224162.41, -1811688.88)  # of EPSG:3832
>>    )+ theme_bw() + filled.contour(data.dfclean$Year)
>>
>>
>> # plot the map of Fiji with the contours lines
>> Fiji
>>
>>
>> ******************************************************************************************************
>>
>> Thanking you in advance
>> sownalc
>>
>> _______________________________________________
>> R-sig-Geo mailing listR-sig-Geo using r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>> --
>> Micha Silver
>> Ben Gurion Univ.
>> Sde Boker, Remote Sensing Lab
>> cell: +972-523-665918
>>
>>
> 	[[alternative HTML version deleted]]
>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> ------------------------------
>
> End of R-sig-Geo Digest, Vol 224, Issue 2
> *****************************************
>



More information about the R-sig-Geo mailing list