Share area of full confidence interval (base graphics)












0















I am using the following code in R to a plot a linear regression with confidence interval bands (95%) around the regression line.



Average <- c(0.298,0.783429,0.2295,0.3725,0.598,0.892,2.4816,2.79975,
1.716368,0.4845,0.974133,0.824,0.936846,1.54905,0.8166,1.83535,
1.6902,1.292667,0.2325,0.801,0.516,2.06645,2.64965,2.04785,0.55075,
0.698615,1.285,2.224118,2.8576,2.42905,1.138143,1.94225,2.467357,0.6615,
0.75,0.547,0.4518,0.8002,0.5936,0.804,0.7,0.6415,0.702182,0.7662,0.847)

Area <-c(8.605,16.079,4.17,5.985,12.419,10.062,50.271,61.69,30.262,11.832,25.099,
8.594,17.786,36.995,7.473,33.531,30.97,30.894,4.894,8.572,5.716,45.5,69.431,
40.736,8.613,14.829,4.963,33.159,66.32,37.513,27.302,47.828,39.286,9.244,19.484,
11.877,9.73,11.542,12.603,9.988,7.737,9.298,14.918,17.632,15)

lm.out <- lm (Area ~ Average)
newx = seq(min(Average), by = 0.05)
conf_interval <- predict(lm.out, newdata = data.frame(Average = newx), interval ="confidence",
level = 0.95)

plot(Average, Area, xlab ="Average", ylab = "Area", main = "Regression")

abline(lm.out, col = "lightblue")

lines(newx, conf_interval[,2], col = "blue", lty ="dashed")
lines(newx, conf_interval[,3], col = "blue", lty ="dashed")


I am stuck because the graph I got reports the bands just for the first part pf the line, leaving out all the remaining line (you find the link to the image at the bottom of the message). What is going wrong? I would also like to shade the area of the confidence interval (not just the lines corresponding to the limits) but I can't understand how to do it.
Any help would be really appreciated, I am completely new in R.












share|improve this question





























    0















    I am using the following code in R to a plot a linear regression with confidence interval bands (95%) around the regression line.



    Average <- c(0.298,0.783429,0.2295,0.3725,0.598,0.892,2.4816,2.79975,
    1.716368,0.4845,0.974133,0.824,0.936846,1.54905,0.8166,1.83535,
    1.6902,1.292667,0.2325,0.801,0.516,2.06645,2.64965,2.04785,0.55075,
    0.698615,1.285,2.224118,2.8576,2.42905,1.138143,1.94225,2.467357,0.6615,
    0.75,0.547,0.4518,0.8002,0.5936,0.804,0.7,0.6415,0.702182,0.7662,0.847)

    Area <-c(8.605,16.079,4.17,5.985,12.419,10.062,50.271,61.69,30.262,11.832,25.099,
    8.594,17.786,36.995,7.473,33.531,30.97,30.894,4.894,8.572,5.716,45.5,69.431,
    40.736,8.613,14.829,4.963,33.159,66.32,37.513,27.302,47.828,39.286,9.244,19.484,
    11.877,9.73,11.542,12.603,9.988,7.737,9.298,14.918,17.632,15)

    lm.out <- lm (Area ~ Average)
    newx = seq(min(Average), by = 0.05)
    conf_interval <- predict(lm.out, newdata = data.frame(Average = newx), interval ="confidence",
    level = 0.95)

    plot(Average, Area, xlab ="Average", ylab = "Area", main = "Regression")

    abline(lm.out, col = "lightblue")

    lines(newx, conf_interval[,2], col = "blue", lty ="dashed")
    lines(newx, conf_interval[,3], col = "blue", lty ="dashed")


    I am stuck because the graph I got reports the bands just for the first part pf the line, leaving out all the remaining line (you find the link to the image at the bottom of the message). What is going wrong? I would also like to shade the area of the confidence interval (not just the lines corresponding to the limits) but I can't understand how to do it.
    Any help would be really appreciated, I am completely new in R.












    share|improve this question



























      0












      0








      0








      I am using the following code in R to a plot a linear regression with confidence interval bands (95%) around the regression line.



      Average <- c(0.298,0.783429,0.2295,0.3725,0.598,0.892,2.4816,2.79975,
      1.716368,0.4845,0.974133,0.824,0.936846,1.54905,0.8166,1.83535,
      1.6902,1.292667,0.2325,0.801,0.516,2.06645,2.64965,2.04785,0.55075,
      0.698615,1.285,2.224118,2.8576,2.42905,1.138143,1.94225,2.467357,0.6615,
      0.75,0.547,0.4518,0.8002,0.5936,0.804,0.7,0.6415,0.702182,0.7662,0.847)

      Area <-c(8.605,16.079,4.17,5.985,12.419,10.062,50.271,61.69,30.262,11.832,25.099,
      8.594,17.786,36.995,7.473,33.531,30.97,30.894,4.894,8.572,5.716,45.5,69.431,
      40.736,8.613,14.829,4.963,33.159,66.32,37.513,27.302,47.828,39.286,9.244,19.484,
      11.877,9.73,11.542,12.603,9.988,7.737,9.298,14.918,17.632,15)

      lm.out <- lm (Area ~ Average)
      newx = seq(min(Average), by = 0.05)
      conf_interval <- predict(lm.out, newdata = data.frame(Average = newx), interval ="confidence",
      level = 0.95)

      plot(Average, Area, xlab ="Average", ylab = "Area", main = "Regression")

      abline(lm.out, col = "lightblue")

      lines(newx, conf_interval[,2], col = "blue", lty ="dashed")
      lines(newx, conf_interval[,3], col = "blue", lty ="dashed")


      I am stuck because the graph I got reports the bands just for the first part pf the line, leaving out all the remaining line (you find the link to the image at the bottom of the message). What is going wrong? I would also like to shade the area of the confidence interval (not just the lines corresponding to the limits) but I can't understand how to do it.
      Any help would be really appreciated, I am completely new in R.












      share|improve this question
















      I am using the following code in R to a plot a linear regression with confidence interval bands (95%) around the regression line.



      Average <- c(0.298,0.783429,0.2295,0.3725,0.598,0.892,2.4816,2.79975,
      1.716368,0.4845,0.974133,0.824,0.936846,1.54905,0.8166,1.83535,
      1.6902,1.292667,0.2325,0.801,0.516,2.06645,2.64965,2.04785,0.55075,
      0.698615,1.285,2.224118,2.8576,2.42905,1.138143,1.94225,2.467357,0.6615,
      0.75,0.547,0.4518,0.8002,0.5936,0.804,0.7,0.6415,0.702182,0.7662,0.847)

      Area <-c(8.605,16.079,4.17,5.985,12.419,10.062,50.271,61.69,30.262,11.832,25.099,
      8.594,17.786,36.995,7.473,33.531,30.97,30.894,4.894,8.572,5.716,45.5,69.431,
      40.736,8.613,14.829,4.963,33.159,66.32,37.513,27.302,47.828,39.286,9.244,19.484,
      11.877,9.73,11.542,12.603,9.988,7.737,9.298,14.918,17.632,15)

      lm.out <- lm (Area ~ Average)
      newx = seq(min(Average), by = 0.05)
      conf_interval <- predict(lm.out, newdata = data.frame(Average = newx), interval ="confidence",
      level = 0.95)

      plot(Average, Area, xlab ="Average", ylab = "Area", main = "Regression")

      abline(lm.out, col = "lightblue")

      lines(newx, conf_interval[,2], col = "blue", lty ="dashed")
      lines(newx, conf_interval[,3], col = "blue", lty ="dashed")


      I am stuck because the graph I got reports the bands just for the first part pf the line, leaving out all the remaining line (you find the link to the image at the bottom of the message). What is going wrong? I would also like to shade the area of the confidence interval (not just the lines corresponding to the limits) but I can't understand how to do it.
      Any help would be really appreciated, I am completely new in R.









      r






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 '18 at 12:30









      hrbrmstr

      61.8k694154




      61.8k694154










      asked Nov 26 '18 at 10:34









      SilviaSilvia

      61




      61
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This is very easy with the ggplot2 -library. Here is the code:



          library(ggplot2)
          data = data.frame(Average, Area)
          ggplot(data=data, aes(x=Area, y=Average))+
          geom_smooth(method="lm", level=0.95)+
          geom_point()


          Code to install the library:



          install.packages("ggplot2")





          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%2f53479239%2fshare-area-of-full-confidence-interval-base-graphics%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 is very easy with the ggplot2 -library. Here is the code:



            library(ggplot2)
            data = data.frame(Average, Area)
            ggplot(data=data, aes(x=Area, y=Average))+
            geom_smooth(method="lm", level=0.95)+
            geom_point()


            Code to install the library:



            install.packages("ggplot2")





            share|improve this answer




























              0














              This is very easy with the ggplot2 -library. Here is the code:



              library(ggplot2)
              data = data.frame(Average, Area)
              ggplot(data=data, aes(x=Area, y=Average))+
              geom_smooth(method="lm", level=0.95)+
              geom_point()


              Code to install the library:



              install.packages("ggplot2")





              share|improve this answer


























                0












                0








                0







                This is very easy with the ggplot2 -library. Here is the code:



                library(ggplot2)
                data = data.frame(Average, Area)
                ggplot(data=data, aes(x=Area, y=Average))+
                geom_smooth(method="lm", level=0.95)+
                geom_point()


                Code to install the library:



                install.packages("ggplot2")





                share|improve this answer













                This is very easy with the ggplot2 -library. Here is the code:



                library(ggplot2)
                data = data.frame(Average, Area)
                ggplot(data=data, aes(x=Area, y=Average))+
                geom_smooth(method="lm", level=0.95)+
                geom_point()


                Code to install the library:



                install.packages("ggplot2")






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 26 '18 at 11:03









                Aaro ViertiöAaro Viertiö

                1295




                1295
































                    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%2f53479239%2fshare-area-of-full-confidence-interval-base-graphics%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

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin