simplified

This commit is contained in:
dchakro 2023-08-22 13:46:49 -07:00
parent 949ee59554
commit e344473f7d

View file

@ -1,4 +1,7 @@
returnPalette <- function(ColorVariable = NULL, GNE.colors = F) {
returnPalette <-
function(ColorVariable = NULL,
GNE.colors = F,
jumble = T) {
# #<---------------------------->
# # You must include this section when:
# # Distributing, Using and/or Modifying this code.
@ -18,11 +21,16 @@ returnPalette <- function(ColorVariable = NULL, GNE.colors = F) {
if (class(ColorVariable) == "character") {
colorsNeeded <- length(unique(ColorVariable))
}
if (class(ColorVariable) == "factor") {
colorsNeeded <- length(levels(ColorVariable))
}
if (colorsNeeded < 1) {
myPalette <- c("#DD0000")
warning("Nothing to return color for.")
}
if (colorsNeeded > 1 & colorsNeeded < 10 & GNE.colors == T) {
if (colorsNeeded > 1 &
colorsNeeded < 10 & GNE.colors == T) {
myPalette <-
c(
"#003087",
@ -41,38 +49,20 @@ returnPalette <- function(ColorVariable = NULL, GNE.colors = F) {
palette = "Classic Tableau")
} else if (colorsNeeded >= 10 & colorsNeeded < 18) {
set.seed(2023)
myPalette <- c(palette.colors(n = 10,
myPalette <- c(
palette.colors(n = 10,
palette = "Classic Tableau"),
palette.colors(n = colorsNeeded - 10,
palette = "Set3"))
palette = "Set3")
)
set.seed(2023)
myPalette <- sample(myPalette)
} else if (colorsNeeded >= 18) {
} else if (colorsNeeded >= 18 & jumble) {
myPalette <- sample(hcl.colors(n = colorsNeeded,
palette = "Spectral"))
}
}
if (class(ColorVariable) == "factor") {
colorsNeeded <- length(levels(ColorVariable))
if (colorsNeeded < 1) {
myPalette <- c("#DD0000")
warning("Nothing to return color for.")
}
if (colorsNeeded > 1 & colorsNeeded < 10) {
myPalette <- palette.colors(n = colorsNeeded,
palette = "Classic Tableau")
} else if (colorsNeeded >= 10 & colorsNeeded < 18) {
set.seed(2023)
myPalette <- c(palette.colors(n = 10,
palette = "Classic Tableau"),
palette.colors(n = colorsNeeded - 10,
palette = "Set2"))
set.seed(2023)
myPalette <- sample(myPalette)
} else if (colorsNeeded >= 18) {
myPalette <- sample(hcl.colors(n = colorsNeeded,
palette = "Spectral"))
}
} else if (colorsNeeded >= 18 & !jumble) {
myPalette <- hcl.colors(n = colorsNeeded,
palette = "Spectral")
}
return(myPalette)
}