Last active
November 17, 2020 22:46
-
-
Save MCMaurer/fefb33472ebefef518f94c1b17cfc4ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download file from here: https://www.dragoart.com/tuts/10861/2/1/86731/how-to-draw-a-conehead-katydid,-conehead-katydid-step-9.htm | |
# right click on the black and white drawing, and "save as" to a folder, it should save as a JPEG | |
library(raster) | |
library(tidyverse) | |
# make a raster from your downloaded image | |
test_raster <- raster("../../Downloads/katydid.jpg") | |
# extract the coordinates with a low value (black lines from the original drawing) | |
coords <- coordinates(test_raster)[values(test_raster) < 200,] | |
# turn it into a data.frame, but only use every 20th value (can tweak depending on how sparse you want the scatter) | |
coords_df <- as.data.frame(coords)[c(rep(FALSE,19), TRUE),] | |
# there's a weird chunk at the bottom of the image, so I'm just cutting it off by taking only y values that are above it | |
coords_df <- coords_df[coords_df$y > 45,] | |
# plot with some jitter to look more scatter-y. Probably wanna tweak this a bit depending on how you want it to look. | |
ggplot(coords_df, aes(x = x, y = y))+ | |
geom_jitter(width = 5, height = 5)+ | |
theme_bw() | |
# if you want to plot in base and still get the "scattery" look, I think you could just add some noise to every X and Y coordinate in coords_df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment