Arcadia-Science / arcadiathemeR

Package for creating ggplot style plots in R that adhere to Arcadia Science style guidelines
Other
1 stars 0 forks source link

Fix main color palettes and add gradient palettes #21

Closed elizabethmcd closed 3 months ago

elizabethmcd commented 3 months ago

This PR modifies the main color palettes from the old accent, accent_expanded etc. to primary, secondary, and sets of main colors. This PR also adds the gradient palettes and functions for adding these gradients to plots of continuous data. This also adds functions to view the color palette options for the main and gradient palettes and returns vectors of the hex codes comprising each palette. This PR addresses #4 and I think the main issue of #20

taylorreiter commented 3 months ago

Added a variety of questions / suggestions! Can you generate gradients with colors at specified positions in R?

I just had to figure this out w/ Audrey for a pub figure. Including my full code below as an example (including dataset gen) in case its helpful!

library(tidyverse)
library(reshape2)
library(scales) 
library(arcadiathemeR)
library(RColorBrewer)

data <- data.frame(
  Tool = c("plm-utils\n(RNAChallenge)", "plm-utils\n(reduced RNAChallenge)", "RNAsamba\n(Homo sapiens model)", 
           "longdist\n(Homo sapiens model)", "NCResNet\n(Homo sapiens model)", 
           "All tools*\n(averages)"),
  MCC = c(-0.44, -0.50, -0.72, -0.27, -0.02, -0.79)
)

mcc_colors <- c("#9E3F41", "#C85152", "#FFF3F4")  # cinnabar, dragon, blush
mcc_positions <- c(0.0, 0.212, 1.0)

mcc_gradient <- colorRampPalette(mcc_colors)

mcc_data <- subset(melted_data, variable == "MCC")

mcc_data$Tool <- factor(mcc_data$Tool, 
                        levels = c("All tools*\n(averages)", 
                                   "NCResNet\n(Homo sapiens model)", "longdist\n(Homo sapiens model)", 
                                   "RNAsamba\n(Homo sapiens model)", "plm-utils\n(reduced RNAChallenge)",
                                   "plm-utils\n(RNAChallenge)"))

mcc_heatmap <- ggplot(mcc_data, aes(x = variable, y = Tool, fill = value)) +
  geom_tile() +
  geom_text(aes(label = round(value, 2)), color = "black", size = 3) +
  scale_fill_gradientn(colors = mcc_colors, values = scales::rescale(mcc_positions)) +
  theme_arcadia() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = "bottom") +
  labs(x = "", y = "", title = "MCC Heatmap", fill = "MCC score")

mcc_heatmap
elizabethmcd commented 3 months ago

@mezarque I haven't finished adding the positions for the gradients but am working on that now, once that's implemented and working I will merge unless I have issues and need you to re-review