How to plot a extracted raster in proper xy coordinates?












0















I have a ndvi raster. I had to extract the values using a threshold conditon.When I plot the graph of the extracted raster, the x y coordinated are not lat long.



I have tried the ggplot() , also the used rastertopoints and rasterfromXYZ to plot the raster but in vain.
The code is below.
Unable to plot s. xy coordiantes are not lat long.



library(raster)
library(rgdal)
raster <- ("D:/Project/ndvisoybean.tif")
plot(ndvi)
ndvi[is.na(ndvi)] <-0
s <- ndvi[ndvi@data@values<maxValue(ndvi) & ndvi@data@values>0.3*maxValue(ndvi)]


I want a graph of the extracted raster s with proper lat long coordinates in x y.










share|improve this question





























    0















    I have a ndvi raster. I had to extract the values using a threshold conditon.When I plot the graph of the extracted raster, the x y coordinated are not lat long.



    I have tried the ggplot() , also the used rastertopoints and rasterfromXYZ to plot the raster but in vain.
    The code is below.
    Unable to plot s. xy coordiantes are not lat long.



    library(raster)
    library(rgdal)
    raster <- ("D:/Project/ndvisoybean.tif")
    plot(ndvi)
    ndvi[is.na(ndvi)] <-0
    s <- ndvi[ndvi@data@values<maxValue(ndvi) & ndvi@data@values>0.3*maxValue(ndvi)]


    I want a graph of the extracted raster s with proper lat long coordinates in x y.










    share|improve this question



























      0












      0








      0








      I have a ndvi raster. I had to extract the values using a threshold conditon.When I plot the graph of the extracted raster, the x y coordinated are not lat long.



      I have tried the ggplot() , also the used rastertopoints and rasterfromXYZ to plot the raster but in vain.
      The code is below.
      Unable to plot s. xy coordiantes are not lat long.



      library(raster)
      library(rgdal)
      raster <- ("D:/Project/ndvisoybean.tif")
      plot(ndvi)
      ndvi[is.na(ndvi)] <-0
      s <- ndvi[ndvi@data@values<maxValue(ndvi) & ndvi@data@values>0.3*maxValue(ndvi)]


      I want a graph of the extracted raster s with proper lat long coordinates in x y.










      share|improve this question
















      I have a ndvi raster. I had to extract the values using a threshold conditon.When I plot the graph of the extracted raster, the x y coordinated are not lat long.



      I have tried the ggplot() , also the used rastertopoints and rasterfromXYZ to plot the raster but in vain.
      The code is below.
      Unable to plot s. xy coordiantes are not lat long.



      library(raster)
      library(rgdal)
      raster <- ("D:/Project/ndvisoybean.tif")
      plot(ndvi)
      ndvi[is.na(ndvi)] <-0
      s <- ndvi[ndvi@data@values<maxValue(ndvi) & ndvi@data@values>0.3*maxValue(ndvi)]


      I want a graph of the extracted raster s with proper lat long coordinates in x y.







      r coordinates raster






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 29 '18 at 5:58









      Rahul Agarwal

      2,17551027




      2,17551027










      asked Dec 29 '18 at 5:53









      DeepthiDeepthi

      11




      11
























          1 Answer
          1






          active

          oldest

          votes


















          1














          As fa as I know there is no appropriate case to plot lon/lat xy coordinate map if the raster is not WGS84 projection.
          One way is that converting raster layer to WGS84 projection.So that the plot coordiante is lon/lat. It is only appreciate for small map or world map.
          The other way is using coord_map function in ggplot.But the import data must be lon/lat dataframe rather than ohter projection coordinate. So it is low efficiency to plot map. More serous it is very slow when converting data.frame point coordinate to another. this way is only suitable for small width/height raster. Code example:



          Primaly you should convert your raster to WGS84 coordiante.



          df=rasterToPoint(raster_WGS84)
          ggplot(df, aes(y=lon, x=lat, color=values)) +
          geom_point(size=2, shape=15) +
          theme() +
          scale_color_distiller(palette='Spectral') +
          coord_map('lambert', lat0=30, lat1=65, xlim=c(-20, 39), ylim=c(19, 75))


          Summary: If your raster is projected coordinate,such as Albers,lambert rather than lon/lat WGS84 coordiate, it is inconvenient to plot a map with lon/lat xy coodiate.






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53967077%2fhow-to-plot-a-extracted-raster-in-proper-xy-coordinates%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            As fa as I know there is no appropriate case to plot lon/lat xy coordinate map if the raster is not WGS84 projection.
            One way is that converting raster layer to WGS84 projection.So that the plot coordiante is lon/lat. It is only appreciate for small map or world map.
            The other way is using coord_map function in ggplot.But the import data must be lon/lat dataframe rather than ohter projection coordinate. So it is low efficiency to plot map. More serous it is very slow when converting data.frame point coordinate to another. this way is only suitable for small width/height raster. Code example:



            Primaly you should convert your raster to WGS84 coordiante.



            df=rasterToPoint(raster_WGS84)
            ggplot(df, aes(y=lon, x=lat, color=values)) +
            geom_point(size=2, shape=15) +
            theme() +
            scale_color_distiller(palette='Spectral') +
            coord_map('lambert', lat0=30, lat1=65, xlim=c(-20, 39), ylim=c(19, 75))


            Summary: If your raster is projected coordinate,such as Albers,lambert rather than lon/lat WGS84 coordiate, it is inconvenient to plot a map with lon/lat xy coodiate.






            share|improve this answer






























              1














              As fa as I know there is no appropriate case to plot lon/lat xy coordinate map if the raster is not WGS84 projection.
              One way is that converting raster layer to WGS84 projection.So that the plot coordiante is lon/lat. It is only appreciate for small map or world map.
              The other way is using coord_map function in ggplot.But the import data must be lon/lat dataframe rather than ohter projection coordinate. So it is low efficiency to plot map. More serous it is very slow when converting data.frame point coordinate to another. this way is only suitable for small width/height raster. Code example:



              Primaly you should convert your raster to WGS84 coordiante.



              df=rasterToPoint(raster_WGS84)
              ggplot(df, aes(y=lon, x=lat, color=values)) +
              geom_point(size=2, shape=15) +
              theme() +
              scale_color_distiller(palette='Spectral') +
              coord_map('lambert', lat0=30, lat1=65, xlim=c(-20, 39), ylim=c(19, 75))


              Summary: If your raster is projected coordinate,such as Albers,lambert rather than lon/lat WGS84 coordiate, it is inconvenient to plot a map with lon/lat xy coodiate.






              share|improve this answer




























                1












                1








                1







                As fa as I know there is no appropriate case to plot lon/lat xy coordinate map if the raster is not WGS84 projection.
                One way is that converting raster layer to WGS84 projection.So that the plot coordiante is lon/lat. It is only appreciate for small map or world map.
                The other way is using coord_map function in ggplot.But the import data must be lon/lat dataframe rather than ohter projection coordinate. So it is low efficiency to plot map. More serous it is very slow when converting data.frame point coordinate to another. this way is only suitable for small width/height raster. Code example:



                Primaly you should convert your raster to WGS84 coordiante.



                df=rasterToPoint(raster_WGS84)
                ggplot(df, aes(y=lon, x=lat, color=values)) +
                geom_point(size=2, shape=15) +
                theme() +
                scale_color_distiller(palette='Spectral') +
                coord_map('lambert', lat0=30, lat1=65, xlim=c(-20, 39), ylim=c(19, 75))


                Summary: If your raster is projected coordinate,such as Albers,lambert rather than lon/lat WGS84 coordiate, it is inconvenient to plot a map with lon/lat xy coodiate.






                share|improve this answer















                As fa as I know there is no appropriate case to plot lon/lat xy coordinate map if the raster is not WGS84 projection.
                One way is that converting raster layer to WGS84 projection.So that the plot coordiante is lon/lat. It is only appreciate for small map or world map.
                The other way is using coord_map function in ggplot.But the import data must be lon/lat dataframe rather than ohter projection coordinate. So it is low efficiency to plot map. More serous it is very slow when converting data.frame point coordinate to another. this way is only suitable for small width/height raster. Code example:



                Primaly you should convert your raster to WGS84 coordiante.



                df=rasterToPoint(raster_WGS84)
                ggplot(df, aes(y=lon, x=lat, color=values)) +
                geom_point(size=2, shape=15) +
                theme() +
                scale_color_distiller(palette='Spectral') +
                coord_map('lambert', lat0=30, lat1=65, xlim=c(-20, 39), ylim=c(19, 75))


                Summary: If your raster is projected coordinate,such as Albers,lambert rather than lon/lat WGS84 coordiate, it is inconvenient to plot a map with lon/lat xy coodiate.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 29 '18 at 11:51

























                answered Dec 29 '18 at 8:56









                CobinCobin

                333111




                333111






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53967077%2fhow-to-plot-a-extracted-raster-in-proper-xy-coordinates%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas