<html style="direction: ltr;">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style id="bidiui-paragraph-margins" type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
  </head>
  <body bidimailui-charset-is-forced="true" style="direction: ltr;">
    <p><font size="4"><font face="Helvetica, Arial, sans-serif">Hi:</font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif">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.</font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif">Here's
          my version for plotting</font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><font
            face="monospace">library(ggplot2)<br>
            library(sf)<br>
            library(rnaturalearth)<br>
            <br>
            #Draft map of Fiji<br>
            world <- ne_countries(returnclass = "sf")</font></font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><font
            face="monospace">Fiji <- ne_countries(country="Fiji",
            returnclass="sf")<br>
            data.Fdf <- read.csv("DataR.csv")<br>
            # Get rid of that last summary row with no coordinates!<br>
            data.Fdf <- data.Fdf[complete.cases(data.Fdf),]<br>
            data.sf <- st_as_sf(data.Fdf, coords=c("long", "lat"),
            crs="EPSG:4326")<br>
            <br>
            # map of Fiji Islands<br>
            Fiji.plot <- ggplot() +<br>
              geom_sf(data=world) +<br>
              geom_sf(data=Fiji) +    <br>
              geom_sf(data=data.sf, aes(color=Year.1965)) +<br>
              coord_sf(crs = 3832, # <a class="moz-txt-link-freetext" href="https://epsg.io/3832">https://epsg.io/3832</a><br>
                xlim = c(2984265.06, 3539584.72), # limits are taken
            from projected bounds<br>
                ylim = c(-2224162.41, -1811688.88)  # of EPSG:3832<br>
              ) + <br>
              theme_bw()<br>
            <br>
            #Plot map of Fiji  <br>
            Fiji.plot<br>
            <br>
          </font></font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif">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(). <br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif">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. </font></font><br>
      <font size="4"><font face="Helvetica, Arial, sans-serif"><font
            size="4"><font face="Helvetica, Arial, sans-serif">Sorry :-(</font></font></font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif">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.</font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><br>
    </p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"><br>
        </font></font></p>
    <p><font size="4"><font face="Helvetica, Arial, sans-serif"></font></font><br>
    </p>
    <div class="moz-cite-prefix">On 05/04/2022 11:10, sownal chand
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAH5tCz1RJkn_EwtamRvGC2pAC323=JCC+OxyS+oGOjMefyzB_Q@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="auto">
        <div>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr"><br>
            </div>
            <br>
            <br>
            <div dir="ltr">Hello sir/madam,
              <div><br>
              </div>
              <div>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 .</div>
              <div><br>
              </div>
              <div> # Packages</div>
              #if (!require("rspatial"))
              remotes::install_github('rspatial/rspatial')<br>
              library(rspatial)<br>
              library(sp)<br>
              library(rgdal)<br>
              library(rgoes)<br>
              library(raster)<br>
              library(ggplot2)<br>
              <br>
              # Fiji geo data<br>
              # download<br>
              #Draft map of Fiji<br>
              world <- rnaturalearth::ne_countries(scale = "Large",
              returnclass = "sf")<br>
              <br>
              # map of Fiji Islands<br>
              Fiji <- ggplot(data=world) +<br>
                geom_sf() + <br>
                coord_sf(<br>
                  crs = 3832, # <a href="https://epsg.io/3832"
                target="_blank" rel="noreferrer" moz-do-not-send="true"
                class="moz-txt-link-freetext">https://epsg.io/3832</a><br>
                  xlim = c(2984265.06, 3539584.72), # limits are taken
              from projected bounds<br>
                  ylim = c(-2224162.41, -1811688.88)  # of EPSG:3832<br>
                )+ theme_bw()<br>
              <br>
              #Plot map of Fiji  <br>
              Fiji<br>
              <br>
              #read csv data from excel file for contoure analysis<br>
              data.Fdf <-
              read.csv("C://Users/Sownal/Documents/data.csv")<br>
              View(data.Fdf)<br>
              class(data.Fdf)<br>
              <br>
              #remove NA values in the spatial Data Frame<br>
              data.dfclean <- na.omit(data.Fdf) <br>
              data.dfclean<br>
              <br>
              data.dfclean$long <- as.numeric(data$Longitude)<br>
              data.dfclean$lat <- as.numeric(data$Latitude)<br>
              <br>
              # convert data to spatial data fame for spatial analysis
              and raster analysis<br>
              data.FSP <- SpatialPointsDataFrame(data= data.dfclean,
              coords = data.dfclean$lat, data.dfclean$long)<br>
              data.FSP<br>
              #select one years data and overlay contours on the Map of
              Fiji<br>
              <br>
              Fiji <- ggplot(data=world) +<br>
                geom_sf() + <br>
                coord_sf(<br>
                  crs = 3832, # <a href="https://epsg.io/3832"
                target="_blank" rel="noreferrer" moz-do-not-send="true"
                class="moz-txt-link-freetext">https://epsg.io/3832</a><br>
                  xlim = c(2984265.06, 3539584.72), # limits are taken
              from projected bounds<br>
                  ylim = c(-2224162.41, -1811688.88)  # of EPSG:3832<br>
                )+ theme_bw() + filled.contour(data.dfclean$Year)<br>
              <br>
              <br>
              # plot the map of Fiji with the contours lines <br>
              Fiji
              <div><br>
              </div>
              <div>******************************************************************************************************</div>
              <div><br>
              </div>
              <div>Thanking you in advance</div>
              <div>sownalc</div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
R-sig-Geo mailing list
<a class="moz-txt-link-abbreviated" href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a>
<a class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
  </body>
</html>