-
Notifications
You must be signed in to change notification settings - Fork 73
Description
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:
- 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
#############################################################################################
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.