Skip to content

Instantly share code, notes, and snippets.

@chichacha
Created July 27, 2019 22:23
Show Gist options
  • Save chichacha/5ebf38c1505ece5d561ad59f7023b40c to your computer and use it in GitHub Desktop.
Save chichacha/5ebf38c1505ece5d561ad59f7023b40c to your computer and use it in GitHub Desktop.
Experimenting with Raster Image as Background
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)
@chichacha
Copy link
Author

annotate_raster_experiment

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