Press "Enter" to skip to content

Little useless-useful R functions – Making scatter plot from an image

[This article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

Taking a jpg image and converting it to raster, getting pixelized data manipulation of the image and plot a scatter image.

Sound like another useless R function, that can produce a scatter plot in a shape of a logo with a smooth curve.

Example with Amazon logo

So the function is using the image manipulation part:

img % image_quantize(max=2, colorspace = 'gray', dither=TRUE) %>% image_scale(geometry = geometry_size_pixels(width=25, height=20, preserve_aspect=FALSE)) # Image manipulation
mat 180))

Second part consists of data transformation to dataframe:

# Melt data

and last part is a simple ggplot scatter plot:

# draw scatter

As always, complete code is available at Github.

And some examples with famous logos:

And you can see the pattern 🙂


Happy R-ing! And stay healthy.

Be First to Comment

Leave a Reply

Your email address will not be published.