Skip to content

Commit

Permalink
add dataset, update readme, new fig
Browse files Browse the repository at this point in the history
  • Loading branch information
zackarno committed Mar 19, 2021
1 parent 754c449 commit 3e99780
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
*.png
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
Depends:
R (>= 2.10)
69 changes: 27 additions & 42 deletions R/all_cols.R
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@

darkgreys<-c("#FFFFFF",
"#F2F2F2",
"#E3E3E3",
"#D5D5D5",
"#C6C6C6",
"#B6B6B7",
"#A5A5A7",
"#959596",
"#818183",
"#6D6D70",
"#58585A",
"#4F4F50",
"#464647",
"#3E3E3F",
"#353535",
"#2C2C2E",
"#222224",
"#1B1B1B",
"#111111",
"#080808",
"#000000")

reds<-c("#FFFFFF",
"#FEF2F2",
"#FFE3E4",
"#FAD5D6",
"#F9C6C7",
"#F7B7B7",
"#F5A6A6",
"#F49595",
"#F28282",
"#F06E6F",
"#EE5859",
"#D64F50",
"#BE4647",
"#A73E3E",
"#8F3535",
"#772B2C",
"#5F2324",
"#471A1A",
"#301212",
"#170A0A",
"#000000")

singleband<-tibble::tribble(
~darkgreys, ~lightgreys, ~beiges, ~reds, ~oranges, ~yellows, ~lightgreens, ~medgreens, ~lightblues, ~medblues, ~blugrey,
"#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF",
"#F2F2F2", "#FBFBFB", "#FBFAF9", "#FEF2F2", "#FFF7F3", "#FFFFF4", "#F7FAF7", "#F3F6F3", "#F2F9FA", "#EEF3F8", "#F6F7F8",
"#E3E3E3", "#F6F6F6", "#F6F5F2", "#FFE3E4", "#FDEEE4", "#FFFDE7", "#EFF5EE", "#E7ECE6", "#E3F1F6", "#DCE5EF", "#ECEEEF",
"#D5D5D5", "#F3F3F3", "#F2F1EB", "#FAD5D6", "#FDE4D7", "#FFFDDD", "#E6EFE5", "#DAE3D9", "#D5EAF1", "#CAD8E8", "#E2E5E8",
"#C6C6C6", "#EEEEEE", "#EEEBE4", "#F9C6C7", "#FBDBC9", "#FFFBD0", "#DDE9DC", "#CED9CC", "#C5E3EC", "#B6CBDF", "#D8DBDF",
"#B6B6B7", "#E8EAEB", "#E9E6DD", "#F7B7B7", "#FBD3BA", "#FFFBC4", "#D5E4D3", "#C1CFBF", "#B6DAE7", "#A1BCD7", "#CED3D6",
"#A5A5A7", "#E3E6E6", "#E4E1D5", "#F5A6A6", "#FAC8AB", "#FFFBB6", "#CCE0CA", "#B2C4B1", "#A5D2E1", "#8AACCE", "#C3C9CD",
"#959596", "#DFE1E1", "#E1DBCF", "#F49595", "#F9C09A", "#FFF9A9", "#C3DAC1", "#A4B9A2", "#94CCDC", "#729DC6", "#B9BFC5",
"#818183", "#DADCDD", "#DBD6C7", "#F28282", "#F8B488", "#FFF89B", "#B9D4B6", "#93AE91", "#81C3D7", "#568CBC", "#ADB5BC",
"#6D6D70", "#D6D8D9", "#D6D1C1", "#F06E6F", "#F7AA76", "#FFF78B", "#B0CFAC", "#85A281", "#6DBBD2", "#367BB3", "#A1ABB3",
"#58585A", "#D1D3D4", "#D2CBB8", "#EE5859", "#F69E61", "#FFF67A", "#A5C9A1", "#72966E", "#56B3CD", "#0067A9", "#95A0A9",
"#4F4F50", "#BCBEBF", "#BDB7A6", "#D64F50", "#DD8E57", "#E5DD6E", "#94B591", "#678763", "#4CA1B8", "#005D98", "#869098",
"#464647", "#A7A9AA", "#A8A293", "#BE4647", "#C57E4E", "#CCC562", "#84A181", "#5B7858", "#458FA4", "#005287", "#778087",
"#3E3E3F", "#929494", "#938E81", "#A73E3E", "#AC6F43", "#B2AC55", "#738D71", "#50694D", "#3C7D8F", "#004876", "#687076",
"#353535", "#7D7F7F", "#7D7A6E", "#8F3535", "#945F39", "#999449", "#637961", "#445A43", "#346B7B", "#003F65", "#596165",
"#2C2C2E", "#68696A", "#69655C", "#772B2C", "#7B4F30", "#7F7B3D", "#526450", "#394C38", "#2C5966", "#003354", "#4A5054",
"#222224", "#545455", "#54504A", "#5F2324", "#623F27", "#666231", "#424F40", "#2D3B2C", "#224952", "#002844", "#3C4144",
"#1B1B1B", "#3F3F41", "#3F3D37", "#471A1A", "#4B2F1D", "#4B4B25", "#313B30", "#222C22", "#19373D", "#002033", "#2E3132",
"#111111", "#2A2A2A", "#2A2925", "#301212", "#312014", "#323117", "#202720", "#161E16", "#102429", "#001422", "#1E2022",
"#080808", "#151515", "#151510", "#170A0A", "#19110A", "#19190C", "#101510", "#0A0F0A", "#0A1115", "#000A11", "#0E1111",
"#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000"
)
nrow(singleband)

59 changes: 40 additions & 19 deletions R/palettes.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@




reach_colors <- c(
`lightred` = "#f7cccdff",
`darkred` = "#EE5859",
`lightgrey` = "#eeefeeff",
`darkgrey` = "#58585A",
`lightbeige` = "#f4f2ecff",
`darkbeige`="#d9d3c2ff",
`lightgreen`= "#A5C9A1",
`orange` = "#F69E61",
`yellow`= "#FFF67A",
`medgreen`= "#72966E",
`lightblue` = "#56B3CD",
`medblue` = "#0067A9"
`lightred` = singleband$reds[2],
`medred` = singleband$reds[11],
`darkred` = singleband$reds[18],
`lightgrey` = singleband$darkgreys[2],
`medgrey` = singleband$darkgreys[11],
`darkgrey` = singleband$darkgreys[18],
`lightbeige` = singleband$beiges[2],
`medbeige` = singleband$beiges[11],
`darkbeige` = singleband$beiges[18],
`lightgreen` = singleband$lightgreens[2],
`green` = singleband$lightgreens[11],
`darkgreen` = singleband$lightgreens[18],
`lightyellow` = singleband$yellows[2],
`medyellow` = singleband$yellows[11],
`darkyellow` = singleband$yellows[18],
`lightorange` = singleband$oranges[2],
`medorange` = singleband$oranges[11],
`darkorange` = singleband$oranges[18],
`lightblue` = singleband$lightblues[2],
`medblue` = singleband$lightblues[11],
`darkblue` = singleband$lightblues[18]
)


Expand All @@ -25,10 +37,19 @@ reach_cols <- function(...) {
}

reach_palettes<- list(
`main` = reach_cols("darkred", "darkbeige","darkgrey"),
`reds` = reds,
# `reds` = reach_cols("light","darkred"),
`beiges` = reach_cols("lightbeige","darkbeige"),
`classic` = reach_cols("medred", "medbeige", "medgrey"),
`classic_extended` = reach_cols("medred", "medbeige", "medgrey", "medorange", "medgreen","medblue"),
`cool_to_hot` = reach_cols("lightgreen", "darkred"),
`darkgrey`= singleband$darkgreys,
`lightgreys`= singleband$lightgreys,
`beiges`= singleband$beiges,
`reds` = singleband$reds,
`oranges` = singleband$oranges,
`yellows` = singleband$yellows,
`lightgreens` = singleband$lightgreens,
`medgreens` = singleband$medgreens,
`lightblues` = singleband$lightblues,
`medblues` = singleband$medblues,
`greys` = reach_cols("lightgrey","darkgrey")
)

Expand All @@ -38,7 +59,7 @@ reach_palettes<- list(
#' @param reverse Boolean indicating whether the palette should be reversed
#' @param ... Additional arguments to pass to colorRampPalette()
#' @export
reach_pal <- function(palette = "main", reverse = FALSE, ...) {
reach_pal <- function(palette = "classic", reverse = FALSE, ...) {
pal <- reach_palettes[[palette]]

if (reverse) pal <- rev(pal)
Expand All @@ -57,7 +78,7 @@ reach_pal <- function(palette = "main", reverse = FALSE, ...) {
#' @param ... Additional arguments to pass to colorRampPalette()
#' @export

scale_color_reach <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
scale_color_reach <- function(palette = "classic", discrete = TRUE, reverse = FALSE, ...) {
pal <- reach_pal(palette = palette, reverse = reverse)

if (discrete) {
Expand All @@ -78,7 +99,7 @@ scale_color_reach <- function(palette = "main", discrete = TRUE, reverse = FALSE
#' @param reverse Boolean indicating whether the palette should be reversed
#' @param ... Additional arguments to pass to colorRampPalette()
#' @export
scale_fill_reach <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
scale_fill_reach <- function(palette = "classic", discrete = TRUE, reverse = FALSE, ...) {
pal <- reach_pal(palette = palette, reverse = reverse)

if (discrete) {
Expand Down
18 changes: 17 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,29 @@ iris %>%
theme_bw()
```

Often when assessment data is crunched (via butteR or HypegrammaR) the results are a long format data set. These long format datasets are also very easily piped into ggplot. The **scale_fill_reach** function will fill barplot with REACH-palette colors

```{r assessment_results_discrete}
assessment_results %>%
filter(variable=="i.income_cat") %>%
ggplot(aes(x=variable_val,y=`mean/pct`, fill=subset_1_val))+
geom_bar(stat="identity",position=position_dodge(width=0.9))+
coord_flip()+
scale_fill_reach()+
theme_bw()+
theme(
legend.title = element_blank()
)
```

### Continuous color scale
To get a continuous color scale you need to specify discrete as F and specify a REACH palette you want to use
```{r continuous color}
iris %>%
ggplot(aes(x=Sepal.Length,y=Sepal.Width, color=Sepal.Width))+
geom_point()+
scale_color_reach(palette = "reds",discrete = F)+
scale_color_reach(palette = "oranges",discrete = F)+
theme_bw()
```

Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ iris %>%

<img src="man/figures/README-discrete_color-1.png" width="100%" />

Often when assessment data is crunched (via butteR or HypegrammaR) the
results are a long format data set. These long format datasets are also
very easily piped into ggplot. The **scale\_fill\_reach** function will
fill barplot with REACH-palette colors

``` r
assessment_results %>%
filter(variable=="i.income_cat") %>%
ggplot(aes(x=variable_val,y=`mean/pct`, fill=subset_1_val))+
geom_bar(stat="identity",position=position_dodge(width=0.9))+
coord_flip()+
scale_fill_reach()+
theme_bw()+
theme(
legend.title = element_blank()
)
```

<img src="man/figures/README-assessment_results_discrete-1.png" width="100%" />

### Continuous color scale

To get a continuous color scale you need to specify discrete as F and
Expand All @@ -53,7 +73,7 @@ specify a REACH palette you want to use
iris %>%
ggplot(aes(x=Sepal.Length,y=Sepal.Width, color=Sepal.Width))+
geom_point()+
scale_color_reach(palette = "reds",discrete = F)+
scale_color_reach(palette = "oranges",discrete = F)+
theme_bw()
```

Expand Down
Binary file added data/assessment_results.rda
Binary file not shown.
Binary file modified man/figures/README-continuous color-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-discrete_color-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3e99780

Please sign in to comment.