library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(RColorBrewer)
n=500
m=50
w=sapply(seq(from=-3.5*pi, to=3.5*pi, length.out=n), function(x) {abs(sin(x))})
x=c(1)
for (i in 2:n) {x[i]=x[i-1]+1/2*(w[i-1]+w[i])}
expand.grid(x=x, y=1:m) %>%
mutate(w=rep(w, m))-> df
opt=theme(legend.position="none",
panel.background = element_rect(fill="white"),
panel.grid=element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(),
axis.text=element_blank())
dim(df)
## [1] 25000 3
ggplot(df, aes(x=x,y=y))+geom_tile(aes(fill=x, width=w))+
scale_fill_gradient(low=brewer.pal(9, "Greens")[1], high=brewer.pal(9, "Greens")[9])+
coord_polar(start = runif(1, min = 0, max = 2*pi))+opt

ggplot(df, aes(x=x,y=y))+geom_tile(aes(fill=w, width=w))+
scale_fill_gradient(low=brewer.pal(9, "Reds")[1], high=brewer.pal(9, "Reds")[9])+
coord_polar(start = runif(1, min = 0, max = 2*pi))+opt

ggplot(df, aes(x=x,y=y))+geom_tile(aes(fill=y, width=w))+
scale_fill_gradient(low=brewer.pal(9, "Purples")[1], high=brewer.pal(9, "Purples")[9])+
coord_polar(start = runif(1, min = 0, max = 2*pi))+opt

ggplot(df, aes(x=x,y=y))+geom_tile(aes(fill=w*y, width=w))+
scale_fill_gradient(low=brewer.pal(9, "Blues")[9], high=brewer.pal(9, "Blues")[1])+
coord_polar(start = runif(1, min = 0, max = 2*pi))+opt

#ref https://fronkonstin.com/tag/rcolorbrewer/