Image labels in levelplot animation R












0















Using the example from the question here , How can one possibly useyears as title for each image?



Example:



library(raster)
library(rasterVis)
library(animation)
library(classInt)

r <- raster(ncol=40, nrow=20)
r <- rnorm(n=ncell(r))
s <- stack(x=c(r, r*r, r*r*r, r*r*r*r))

classes <- classIntervals(values(r), n=5, style="fisher", precision = 3)
brks <- classes$brks
brks <- round(brks, 2)

saveGIF({
for(i in c(1:nlayers(s))){
l <- levelplot(s[[i]], colorkey=list(at=brks, labels=c(as.character(brks))), margin=FALSE,main=noquote(paste("",i)))
plot(l)
}
}, interval=0.2, movie.name="animation.gif")


The line main=noquote(paste("",i)) will label each image in the animation as 1,2,3, etc... However, I would like to use 1919, 1920, 1921, etc.. instead. Is another for loop needed to generate 1919, 1920, 1921, etc..?



The following do not work:



main=paste(1919,i)
main=paste(1919:1923,i)


My actual rasterbrick has 100 layers



Any suggestions for using the year as title for each image in the animation?










share|improve this question



























    0















    Using the example from the question here , How can one possibly useyears as title for each image?



    Example:



    library(raster)
    library(rasterVis)
    library(animation)
    library(classInt)

    r <- raster(ncol=40, nrow=20)
    r <- rnorm(n=ncell(r))
    s <- stack(x=c(r, r*r, r*r*r, r*r*r*r))

    classes <- classIntervals(values(r), n=5, style="fisher", precision = 3)
    brks <- classes$brks
    brks <- round(brks, 2)

    saveGIF({
    for(i in c(1:nlayers(s))){
    l <- levelplot(s[[i]], colorkey=list(at=brks, labels=c(as.character(brks))), margin=FALSE,main=noquote(paste("",i)))
    plot(l)
    }
    }, interval=0.2, movie.name="animation.gif")


    The line main=noquote(paste("",i)) will label each image in the animation as 1,2,3, etc... However, I would like to use 1919, 1920, 1921, etc.. instead. Is another for loop needed to generate 1919, 1920, 1921, etc..?



    The following do not work:



    main=paste(1919,i)
    main=paste(1919:1923,i)


    My actual rasterbrick has 100 layers



    Any suggestions for using the year as title for each image in the animation?










    share|improve this question

























      0












      0








      0








      Using the example from the question here , How can one possibly useyears as title for each image?



      Example:



      library(raster)
      library(rasterVis)
      library(animation)
      library(classInt)

      r <- raster(ncol=40, nrow=20)
      r <- rnorm(n=ncell(r))
      s <- stack(x=c(r, r*r, r*r*r, r*r*r*r))

      classes <- classIntervals(values(r), n=5, style="fisher", precision = 3)
      brks <- classes$brks
      brks <- round(brks, 2)

      saveGIF({
      for(i in c(1:nlayers(s))){
      l <- levelplot(s[[i]], colorkey=list(at=brks, labels=c(as.character(brks))), margin=FALSE,main=noquote(paste("",i)))
      plot(l)
      }
      }, interval=0.2, movie.name="animation.gif")


      The line main=noquote(paste("",i)) will label each image in the animation as 1,2,3, etc... However, I would like to use 1919, 1920, 1921, etc.. instead. Is another for loop needed to generate 1919, 1920, 1921, etc..?



      The following do not work:



      main=paste(1919,i)
      main=paste(1919:1923,i)


      My actual rasterbrick has 100 layers



      Any suggestions for using the year as title for each image in the animation?










      share|improve this question














      Using the example from the question here , How can one possibly useyears as title for each image?



      Example:



      library(raster)
      library(rasterVis)
      library(animation)
      library(classInt)

      r <- raster(ncol=40, nrow=20)
      r <- rnorm(n=ncell(r))
      s <- stack(x=c(r, r*r, r*r*r, r*r*r*r))

      classes <- classIntervals(values(r), n=5, style="fisher", precision = 3)
      brks <- classes$brks
      brks <- round(brks, 2)

      saveGIF({
      for(i in c(1:nlayers(s))){
      l <- levelplot(s[[i]], colorkey=list(at=brks, labels=c(as.character(brks))), margin=FALSE,main=noquote(paste("",i)))
      plot(l)
      }
      }, interval=0.2, movie.name="animation.gif")


      The line main=noquote(paste("",i)) will label each image in the animation as 1,2,3, etc... However, I would like to use 1919, 1920, 1921, etc.. instead. Is another for loop needed to generate 1919, 1920, 1921, etc..?



      The following do not work:



      main=paste(1919,i)
      main=paste(1919:1923,i)


      My actual rasterbrick has 100 layers



      Any suggestions for using the year as title for each image in the animation?







      r animation raster levelplot






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 15:51









      code123code123

      7481629




      7481629
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This worked for me after a few thoughts:



          main=paste(" ", 1918+i, sep='')


          Assuming my data starts in 1919, sequential years with a step of 1 will be added to each image.






          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%2f53304054%2fimage-labels-in-levelplot-animation-r%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









            0














            This worked for me after a few thoughts:



            main=paste(" ", 1918+i, sep='')


            Assuming my data starts in 1919, sequential years with a step of 1 will be added to each image.






            share|improve this answer




























              0














              This worked for me after a few thoughts:



              main=paste(" ", 1918+i, sep='')


              Assuming my data starts in 1919, sequential years with a step of 1 will be added to each image.






              share|improve this answer


























                0












                0








                0







                This worked for me after a few thoughts:



                main=paste(" ", 1918+i, sep='')


                Assuming my data starts in 1919, sequential years with a step of 1 will be added to each image.






                share|improve this answer













                This worked for me after a few thoughts:



                main=paste(" ", 1918+i, sep='')


                Assuming my data starts in 1919, sequential years with a step of 1 will be added to each image.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 23:19









                code123code123

                7481629




                7481629
































                    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%2f53304054%2fimage-labels-in-levelplot-animation-r%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

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues