Skip to content

Instantly share code, notes, and snippets.

@chichacha
Created January 15, 2019 06:19
Show Gist options
  • Save chichacha/fd130a03631cb47323a846e6b7dc1657 to your computer and use it in GitHub Desktop.
Save chichacha/fd130a03631cb47323a846e6b7dc1657 to your computer and use it in GitHub Desktop.
Peacock + ggplot Experiment
library(tidyverse)
library(imager)
library(scales)
peacock <- load.image("https://farm9.staticflickr.com/8126/8647827542_3f55baed69_z.jpg")
peacock_df <- peacock %>%
RGBtoHSV() %>%
as.data.frame(wide="c") %>% filter(x%%3==0&y%%3==0) %>%
mutate(hex=hsv(rescale(c.1, from=c(0,360)),c.2,c.3))
peacock_df %>% ggplot(aes(x=x,y=y)) +
geom_spoke(aes(angle=rescale(c.1,from=c(0,360),to=c(0,2*pi)),
radius=(c.2)*10,size=c.3*2, color=str_c(hex,"de")),
lineend="butt") +
coord_fixed() +
scale_y_reverse() +
theme_void() +
scale_color_identity() +
scale_size_identity()
ggsave("peacock_geom_spoke.png",width=16, height=12)
peacock_df %>% ggplot(aes(x=x,y=y)) +
geom_point(aes(color=hex,size=c.2*3,alpha=c.3),shape=1) +
coord_fixed() +
scale_y_reverse() +
theme_void() +
scale_color_identity() +
scale_size_identity() +
scale_alpha_identity()
ggsave("peacock_geom_point_shape1.png",width=16, height=12)
peacock_df %>% sample_n(size=3000) %>%
ggplot(aes(x=x,y=y)) +
geom_tile(aes(fill=hex, width=100*c.2, height=100*c.3, alpha=0.3)) +
coord_fixed() +
scale_y_reverse() +
theme_void() +
scale_fill_identity() +
scale_size_identity() +
scale_alpha_identity()
ggsave("peacock_geom_tile.png",width=16, height=12)
@chichacha
Copy link
Author

peacock_geom_spoke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment