Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My question is, How to colorize "Heatmap", creating a function with "ifelse ()"????? #114

Open
EduardoRamirez8112 opened this issue Jan 21, 2021 · 0 comments

Comments

@EduardoRamirez8112
Copy link

EduardoRamirez8112 commented Jan 21, 2021

How to color "Heatmap", creating a function with "if else ()" ????

hi i am new to using "rpivotTable" package in "r". For data analysis due to its similarity to a rpivotTable in Excel. I have the following drawbacks:

  1. When using the "Heatmap" render, I have come across that it assigns the coloration by scale based on a domain. (https://pivottable.js.org/examples/montreal_2014.html). However, I want to color minimum and maximum. I attach the image with the output of rpivtotTable and the output that I want to get from the R script.

################################################################################################
prueba1<-rpivotTable(Titanic,
rows = c("Survived","Class"),
cols = c("Sex"),vals = c("Class","Freq"),
rendererName = "Row Heatmap",
aggregatorName = "Eficiencia", locale= "en",
aggregators = list(Eficiencia = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum over Sum"]'),
Suma = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum"]')))

prueba1<-htmlwidgets::prependContent(prueba1,htmltools::tags$style(".pvtTotalLabel, .colTotal,
.rowTotal, .pvtGrandTotal { display: none; }"))
prueba1

Outpout from script
#############################################################################################

My question focuses on how I can color the column "Female" using the following conditional: Color green if "Female> = Male" and if "Female <Male" color Female red. I have tried the following functionality but I have only managed to do it with a domain and not how I want it to be using a conditioner. What I have tried is the following:

prueba1<-rpivotTable(Titanic,
rows = c("Survived","Class"),
cols = c("Sex"),vals = c("Class","Freq"),
rendererName = "Row Heatmap",
rendererOptions = list(
heatmap = list(
colorScaleGenerator = htmlwidgets::JS('function(values) {
return d3.scale.linear().domain([0, 0.015, 1])
.range(["#FF0000", "#FFFFFF", "#14B904"])}'))),
aggregatorName = "Eficiencia", locale= "en",
aggregators = list(Eficiencia = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum over Sum"]'),
Suma = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum"]')))

prueba1$x$params$rendererOptions=prueba1$x$params$rendererOptions[[1]]

prueba1<-htmlwidgets::prependContent(prueba1,htmltools::tags$style(".pvtTotalLabel, .colTotal,
.rowTotal, .pvtGrandTotal { display: none; }"))
prueba1

################################################################

RESULT THAT I AM LOOKING TO OBTAIN

This is how I am trying to get the pivotTable, without any success. This result is obtained by modifying the code of the "html" file, however I want it to be inside the code of the "R" script.

desired output

@EduardoRamirez8112 EduardoRamirez8112 changed the title How to colorize "Heatmap", creating a function with "ifelse ()". My question is, How to colorize "Heatmap", creating a function with "ifelse ()"????? Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant