teunbrand / ggchromatic Goto Github PK
View Code? Open in Web Editor NEWColour and fill scales for 'ggplot2' using colour spaces.
Home Page: https://teunbrand.github.io/ggchromatic/
License: Other
Colour and fill scales for 'ggplot2' using colour spaces.
Home Page: https://teunbrand.github.io/ggchromatic/
License: Other
I think custom color scales are important for multidimensional color scales, because different colorspaces imply different dependencies of the differente channels amongst each other, and create different "perceptual correlations" in the viewer. Therefore being able to create a custom made colorspace for a particular application is useful.
When trying to do so with the package I first had the impression that it is very difficult to do due to its (at first sight) tight integration with the farver package, which quickly leads one to calls of c/c++ functions.
Then later I found out that it's actually quite simple to implement a custom colorspace. It would be great it the welcome page listed one such example to show how simple it can be and to give users a headstart.
Here's a simple example, probably not in full production quality. It could be used as a basis to make a good example for the starting page.
library(tidyverse)
library(ggchromatic)
# define a custom palette function
ab_spec=
function(observationEffort=double(),nDetections=double()){
ggchromatic:::new_colour_spec(
observationEffort=observationEffort
,nDetections=nDetections
,class="ab_spec"
)
}
ab_palette=
function (x, min = 0, max = 1)
{
x=as.matrix(x)
# print(x)
out=character(nrow(x))
inputsWithNA=is.na(x[,"observationEffort"])|is.na(x[,"nDetections"]) # only run rgb() on inputs without NA, as it doesnt have NA-handling implemented. return NA for all inputs that contain NA in any channel.
out[inputsWithNA]=NA
out[!inputsWithNA]=rgb(x[!inputsWithNA,"observationEffort"],x[!inputsWithNA,"nDetections"],1-x[!inputsWithNA,"observationEffort"])
out
}
# apply the custom palette
n=30
tibble(observationEffort=(1:n)/n,nDetections=runif(n)) %>%
ggplot()+
geom_point(
aes(
observationEffort
,nDetections
,colour=ab_spec(observationEffort,nDetections)
)
)+
chromatic_scale(
aesthetics="colour"
,name=c("observation effort","number of\ndetections")
,scale_name="ab_scale"
,palette=ab_palette
,prototype=ab_spec
,limits=
list(
observationEffort=c(0,1)
,nDetections=c(0,1)
)
,channel_limits=ab_spec(0:1,0:1)
,expand=0
)
It is missing as of now.
It is still missing.
This issue is for continuing the thread over at teunbrand/ggh4x#29.
Needs implementing
Guide for displaying 3 channels in a cube
I am trying to do a umap graph with 3 genes and I can get the color to work, but then when it has to create the legend it fails with the error:
Error in if (0 <= angle & angle < 90) { : the condition has length >
trace back info:
If i suppress the legend with theme(legend.position='none') I can get the graph to work. Similarly if I only use two genes I can see the graph and the legend.
I made a dataframe with the umap coordinates and the SCT normalized expression for 3 genes. Tried to look at your code to figure out what was wrong with my input. I am running this on a docker image with RStudio with ggplot2 3.4.3.
Here is my code
tes<-subset(immune_combined2, features= c('Zbtb16','Gata3','Rorc'))
FD<-cbind(immune_combined2@reductions$[email protected],t(tes@assays$SCT$data))
FD<-data.frame(FD)
g1<-ggplot(FD, aes(x = umap_1, y = umap_2))+geom_point(aes(colour = rgb_spec(Zbtb16, Gata3, Rorc)))+theme_classic()
Needs implementing
A guide for displaying three channels through colourbars seperately
Do it better.
Since the different channels might serve to visualize very different things, they sometimes need different rescalers.
As far as I can see this currently is not possible, since:
I currently have a project where I want to make use of this feature, because 1 channel contains outliers and must thus be scaled based on quantiles rather then minimum and maximum to give a useful visualisation, whereas the other channel must be guaranteed to include all extreme values and is therefore scaled based on min/max.
As a sidenote: ggplot does not naturally support scaling based on quantiles, as the only info about the data which is passed to the rescaler is the min and max (e.g. when the rescaler is invoked in the legend construction, where no actual data is passed). I'm circumventing this by scoping the full dataset into the rescaler in a separate channel.
Recommended by Hadley himself:
https://twitter.com/hadleywickham/status/1355554099941531650?s=20
To control the output of the individual channels.
Now, you'd have to specify for example:
scale_colour_rgb(
channel_limits = rgb_spec(c(0, 1), c(0.25, 0.75), c(0, 1))
)
It would be nicer if you could just do:
scale_colour_rgb(
channel_limits = list(g = c(0.25, 0.75))
)
The idea is that you can graft a regular palette onto a colourspace palette and adjust chroma/saturation and lightness.
For example, we take the viridis palette as channel 1, put chroma/saturation as channel 2 and lightness as channel 3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.