Created
July 27, 2019 22:23
-
-
Save chichacha/5ebf38c1505ece5d561ad59f7023b40c to your computer and use it in GitHub Desktop.
Experimenting with Raster Image as Background
This file contains hidden or 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
library(tidyverse) | |
## creating raster to use as background | |
## get your favourite colour | |
colpal <- c("#fe4a49", "#2ab7ca", "#fed766", "#e6e6ea", "#f4f4f8") | |
viridis_bg <- matrix(viridis_pal()(150*50),nrow=50) | |
bg <- matrix(colorRampPalette(colpal)(50*50), nrow=50) | |
df_maker <- function(size=100){ | |
x <-sample(c(0:1100), size=size, replace=T) | |
y <-sample(c(0:700), size=size, replace=T) | |
color=sample(colpal, size=size, replace=T) | |
shape=sample(c(1:9), size=size, replace=T) | |
df <- tibble( | |
x=x, | |
y=y, | |
color=color, | |
shape=shape | |
) | |
return(df) | |
} | |
df <- df_maker(1000) | |
ggplot(df,aes(x=x,y=y)) + | |
annotation_raster(bg,xmin=-Inf,xmax=Inf,ymin=-Inf, ymax=Inf) + | |
geom_point(aes(color=color), size=10, shape=4) + | |
theme_void() + | |
scale_color_identity() | |
ggsave("annotate_raster_experiment.png", width=11, height=9) | |
Author
chichacha
commented
Jul 27, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment