extracting hex colors form jpeg, store in data.frame, and then plotting with ggplot












0















Like the title says. I have an image that I want to extract the hex values for the color, store in a data.frame and then plot using ggplot.



Here's what I have:



library(ggplot2)
aws.logo = 'https://eventil.s3.amazonaws.com/uploads/group/avatar/8626/medium_highres_470196509.jpeg'

temp = tempfile()
download.file(aws.logo, temp, mode = 'wb')

## matrix of colors
y = jpeg::readJPEG(temp)
val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255)
aws.img <- matrix(val, dim(y)[1], dim(y)[2])

out = reshape2::melt(aws.img)
names(out) = c('col', 'row', 'value')
out$value = as.character(out$value)

ggplot(out) +
geom_point(aes(x = row, y = -col), color = out$value) + ## why do I have to flip the order of
theme(legend.position="none") ## col after reshaping?


Why are the colors different from the logo on the website?










share|improve this question



























    0















    Like the title says. I have an image that I want to extract the hex values for the color, store in a data.frame and then plot using ggplot.



    Here's what I have:



    library(ggplot2)
    aws.logo = 'https://eventil.s3.amazonaws.com/uploads/group/avatar/8626/medium_highres_470196509.jpeg'

    temp = tempfile()
    download.file(aws.logo, temp, mode = 'wb')

    ## matrix of colors
    y = jpeg::readJPEG(temp)
    val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255)
    aws.img <- matrix(val, dim(y)[1], dim(y)[2])

    out = reshape2::melt(aws.img)
    names(out) = c('col', 'row', 'value')
    out$value = as.character(out$value)

    ggplot(out) +
    geom_point(aes(x = row, y = -col), color = out$value) + ## why do I have to flip the order of
    theme(legend.position="none") ## col after reshaping?


    Why are the colors different from the logo on the website?










    share|improve this question

























      0












      0








      0








      Like the title says. I have an image that I want to extract the hex values for the color, store in a data.frame and then plot using ggplot.



      Here's what I have:



      library(ggplot2)
      aws.logo = 'https://eventil.s3.amazonaws.com/uploads/group/avatar/8626/medium_highres_470196509.jpeg'

      temp = tempfile()
      download.file(aws.logo, temp, mode = 'wb')

      ## matrix of colors
      y = jpeg::readJPEG(temp)
      val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255)
      aws.img <- matrix(val, dim(y)[1], dim(y)[2])

      out = reshape2::melt(aws.img)
      names(out) = c('col', 'row', 'value')
      out$value = as.character(out$value)

      ggplot(out) +
      geom_point(aes(x = row, y = -col), color = out$value) + ## why do I have to flip the order of
      theme(legend.position="none") ## col after reshaping?


      Why are the colors different from the logo on the website?










      share|improve this question














      Like the title says. I have an image that I want to extract the hex values for the color, store in a data.frame and then plot using ggplot.



      Here's what I have:



      library(ggplot2)
      aws.logo = 'https://eventil.s3.amazonaws.com/uploads/group/avatar/8626/medium_highres_470196509.jpeg'

      temp = tempfile()
      download.file(aws.logo, temp, mode = 'wb')

      ## matrix of colors
      y = jpeg::readJPEG(temp)
      val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255)
      aws.img <- matrix(val, dim(y)[1], dim(y)[2])

      out = reshape2::melt(aws.img)
      names(out) = c('col', 'row', 'value')
      out$value = as.character(out$value)

      ggplot(out) +
      geom_point(aes(x = row, y = -col), color = out$value) + ## why do I have to flip the order of
      theme(legend.position="none") ## col after reshaping?


      Why are the colors different from the logo on the website?







      r ggplot2 jpeg






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 20:49









      R.M.R.M.

      1,0531924




      1,0531924
























          1 Answer
          1






          active

          oldest

          votes


















          0














          the raedJPEG will return RGB color values on the 0/1 scale, not the 0/255 scale. Use



          val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1)


          Also, it's usually better not to have any $ operations in a ggplot call. Something like this would be safer



          ggplot(out) + 
          geom_point(aes(x = row, y = -col, color = value)) +
          theme(legend.position="none") +
          scale_color_identity ()


          enter image description here






          share|improve this answer
























          • If I replace val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255) with val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1) I still get those funky colors. Do I have to replace readJPEG(temp) with something as well?

            – R.M.
            Nov 21 '18 at 22:03











          • This was test with jpeg_0.1-8 and R-3-5-0. Are you using something different? The above works for me with that change.

            – MrFlick
            Nov 21 '18 at 22:20











          • not sure what the issue was, works perfectly now. (R-3-4-3 and jpeg_0.1-8)

            – R.M.
            Nov 26 '18 at 16:22











          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%2f53420262%2fextracting-hex-colors-form-jpeg-store-in-data-frame-and-then-plotting-with-ggp%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














          the raedJPEG will return RGB color values on the 0/1 scale, not the 0/255 scale. Use



          val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1)


          Also, it's usually better not to have any $ operations in a ggplot call. Something like this would be safer



          ggplot(out) + 
          geom_point(aes(x = row, y = -col, color = value)) +
          theme(legend.position="none") +
          scale_color_identity ()


          enter image description here






          share|improve this answer
























          • If I replace val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255) with val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1) I still get those funky colors. Do I have to replace readJPEG(temp) with something as well?

            – R.M.
            Nov 21 '18 at 22:03











          • This was test with jpeg_0.1-8 and R-3-5-0. Are you using something different? The above works for me with that change.

            – MrFlick
            Nov 21 '18 at 22:20











          • not sure what the issue was, works perfectly now. (R-3-4-3 and jpeg_0.1-8)

            – R.M.
            Nov 26 '18 at 16:22
















          0














          the raedJPEG will return RGB color values on the 0/1 scale, not the 0/255 scale. Use



          val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1)


          Also, it's usually better not to have any $ operations in a ggplot call. Something like this would be safer



          ggplot(out) + 
          geom_point(aes(x = row, y = -col, color = value)) +
          theme(legend.position="none") +
          scale_color_identity ()


          enter image description here






          share|improve this answer
























          • If I replace val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255) with val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1) I still get those funky colors. Do I have to replace readJPEG(temp) with something as well?

            – R.M.
            Nov 21 '18 at 22:03











          • This was test with jpeg_0.1-8 and R-3-5-0. Are you using something different? The above works for me with that change.

            – MrFlick
            Nov 21 '18 at 22:20











          • not sure what the issue was, works perfectly now. (R-3-4-3 and jpeg_0.1-8)

            – R.M.
            Nov 26 '18 at 16:22














          0












          0








          0







          the raedJPEG will return RGB color values on the 0/1 scale, not the 0/255 scale. Use



          val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1)


          Also, it's usually better not to have any $ operations in a ggplot call. Something like this would be safer



          ggplot(out) + 
          geom_point(aes(x = row, y = -col, color = value)) +
          theme(legend.position="none") +
          scale_color_identity ()


          enter image description here






          share|improve this answer













          the raedJPEG will return RGB color values on the 0/1 scale, not the 0/255 scale. Use



          val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1)


          Also, it's usually better not to have any $ operations in a ggplot call. Something like this would be safer



          ggplot(out) + 
          geom_point(aes(x = row, y = -col, color = value)) +
          theme(legend.position="none") +
          scale_color_identity ()


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 20:56









          MrFlickMrFlick

          122k11140168




          122k11140168













          • If I replace val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255) with val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1) I still get those funky colors. Do I have to replace readJPEG(temp) with something as well?

            – R.M.
            Nov 21 '18 at 22:03











          • This was test with jpeg_0.1-8 and R-3-5-0. Are you using something different? The above works for me with that change.

            – MrFlick
            Nov 21 '18 at 22:20











          • not sure what the issue was, works perfectly now. (R-3-4-3 and jpeg_0.1-8)

            – R.M.
            Nov 26 '18 at 16:22



















          • If I replace val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255) with val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1) I still get those funky colors. Do I have to replace readJPEG(temp) with something as well?

            – R.M.
            Nov 21 '18 at 22:03











          • This was test with jpeg_0.1-8 and R-3-5-0. Are you using something different? The above works for me with that change.

            – MrFlick
            Nov 21 '18 at 22:20











          • not sure what the issue was, works perfectly now. (R-3-4-3 and jpeg_0.1-8)

            – R.M.
            Nov 26 '18 at 16:22

















          If I replace val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255) with val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1) I still get those funky colors. Do I have to replace readJPEG(temp) with something as well?

          – R.M.
          Nov 21 '18 at 22:03





          If I replace val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 255) with val <- rgb( y[,,1], y[,,2], y[,,3], maxColorValue = 1) I still get those funky colors. Do I have to replace readJPEG(temp) with something as well?

          – R.M.
          Nov 21 '18 at 22:03













          This was test with jpeg_0.1-8 and R-3-5-0. Are you using something different? The above works for me with that change.

          – MrFlick
          Nov 21 '18 at 22:20





          This was test with jpeg_0.1-8 and R-3-5-0. Are you using something different? The above works for me with that change.

          – MrFlick
          Nov 21 '18 at 22:20













          not sure what the issue was, works perfectly now. (R-3-4-3 and jpeg_0.1-8)

          – R.M.
          Nov 26 '18 at 16:22





          not sure what the issue was, works perfectly now. (R-3-4-3 and jpeg_0.1-8)

          – R.M.
          Nov 26 '18 at 16:22




















          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%2f53420262%2fextracting-hex-colors-form-jpeg-store-in-data-frame-and-then-plotting-with-ggp%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

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules