My question is, How to colorize "Heatmap", creating a function with "ifelse ()"????? · Issue #114 · smartinsightsfromdata/rpivotTable · GitHub
Skip to content

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

Open

Description

@EduardoRamirez8112

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

Activity

  1. changed the title [-]How to colorize "Heatmap", creating a function with "ifelse ()".[/-] [+]My question is, How to colorize "Heatmap", creating a function with "ifelse ()"?????[/+] on Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions