logo
down
shadow

Exclude or set a unique color to the bottom triangle of a correlation matrix heatmap


Exclude or set a unique color to the bottom triangle of a correlation matrix heatmap

By : user2174447
Date : October 18 2020, 08:10 AM
This might help you One option would be to not use the complete correlation dataset and filter out only one half of the matrix using upper.tri. You could even consider setting its diag argument to TRUE to get rid of the arguably unnecessary diagonal ones.
How about the below?
code :
# Load data
library(plotly)
data("mtcars")
my_data <- mtcars[, c(1,3,4,5,6,7)]
# print the first 6 rows
head(my_data, 6)
res <- cor(my_data)
res[upper.tri(res)] <- NA
round(res, 2)
plot_ly(x=colnames(res), y=rownames(res), z = res, type = "heatmap") %>%
  layout(
    xaxis=list(tickfont = list(size = 30), tickangle = 45),
    margin = list(l = 150, r = 50, b = 150, t = 0, pad = 4))


Share : facebook icon twitter icon
Heatmap or plot for a correlation matrix

Heatmap or plot for a correlation matrix


By : Andy
Date : March 29 2020, 07:55 AM
around this issue @Lucas provides good advice here as corrplot is quite useful for visualizing correlation matrices. However, it doesn't address the original issue of plotting a large correlation matrix. In fact, corrplot will also fail when trying to visualize this large of a correlation matrix. For a simple solution, you might want to consider reducing the number of variables. That is, I would suggest looking at the correlation between a subset of variables that you know are important for your problem. Trying to understand the correlation structure of that many variables will be a difficult task (even if you can visualize it)!
Lower triangle correlation heatmap

Lower triangle correlation heatmap


By : user6714133
Date : March 29 2020, 07:55 AM
I wish this help you Well, I reproduced your script and this is my plot
Just change
code :
ggplot(cor.mat.df ,aes(sample2, sample1, fill=correlation))+
  geom_tile(color="white")+
  scale_fill_gradient2(low="blue", high="red", mid="white", midpoint=0, limit=c(-1,1), space="Lab", name="Pearson\nCorrelation")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,vjust=1,size=10,hjust=1))+
  coord_fixed()+
  labs(x="",y="")
ggplot(cor.df, aes(sample2, sample1, fill=correlation))+
  geom_tile(color="white")+
  scale_fill_gradient2(low="blue", high="red", mid="white", midpoint=0, limit=c(-1,1), space="Lab", name="Pearson\nCorrelation")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45, vjust=1, size=10, hjust=1))+
  coord_fixed()+
  labs(x="",y="")
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Spanish_Colombia.1252  LC_CTYPE=Spanish_Colombia.1252   
[3] LC_MONETARY=Spanish_Colombia.1252 LC_NUMERIC=C                     
[5] LC_TIME=Spanish_Colombia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_2.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8      digest_0.6.11    assertthat_0.1   grid_3.3.2       plyr_1.8.4      
 [6] gtable_0.2.0     magrittr_1.5     scales_0.4.1     stringi_1.1.2    reshape2_1.4.2  
[11] lazyeval_0.2.0   labeling_0.3     tools_3.3.2      stringr_1.1.0    munsell_0.4.3   
[16] colorspace_1.3-2 tibble_1.2
Using a heatmap to reflect differences between correlation dataframes and displaying only lower triangle

Using a heatmap to reflect differences between correlation dataframes and displaying only lower triangle


By : user508915
Date : March 29 2020, 07:55 AM
this will help I have the above heatmap that I generate using the below: , If p4 is a matrix, you can use upper.tri as:
code :
p4[upper.tri(p4)] <- NA
melt_p4 <- melt(p4)
melt_p4 <- melt_p4[!is.na(melt_p4$value),]

colnames(melt_p4) <- c("Var1", "Var2", "value")

ggplot(melt_p4, aes(Var1, Var2)) +
  geom_tile(aes(fill = value), color = "white") +
  labs(title = "ST - LT Correlation Across Factor") +
  scale_fill_gradient(low = "red", high = "green") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  geom_text(aes(label = round(value, 1)), size = 2.2) +
  theme_bw() +
  scale_x_discrete(expand=c(0,0)) + 
  scale_y_discrete(expand=c(0,0)) 
set.seed(1)
p4 <- matrix(runif(16, 0, 1), nrow = 4, ncol = 4)

row.names(p4) <- c("A", "B", "C", "D")
colnames(p4) <- c("A", "B", "C", "D")
Heatmap of correlation matrix using seaborn not displaying properly at the top and bottom row

Heatmap of correlation matrix using seaborn not displaying properly at the top and bottom row


By : semistandard
Date : March 29 2020, 07:55 AM
This might help you Upgrading matplotlib to the last version (3.1.3) should solve the issue.
using anaconda: conda update matplotlib using pip: pip install -U matplotlib
How to animate a seaborn's heatmap or correlation matrix?

How to animate a seaborn's heatmap or correlation matrix?


By : David Ding
Date : March 29 2020, 07:55 AM
wish helps you I replaced plt.imshow (casting data via set_data didn't work) with seaborn.heatmap.
Related Posts Related Posts :
  • How to define a function that calls shiny functions?
  • How to count number of observations in a "n" dimensional range in R
  • Superimposing asymmetric t-distribution using ggplot2
  • Makefile to render all targets of all .Rmd files in directory
  • Authentication failure with rdrop2
  • DT data table display error
  • Issue when adding new rows (with nested dataframes within) to a dataframe
  • R-How to compare two dataframe and update list column value
  • Series vector for approximating pi
  • what is difference between "variance explained " in Random Forest and "merror" in XGBoost
  • R - Cast dataframe on unique rows - reshape2
  • ggplot2: plot correct proportions using geom_bar
  • Speedup query for R data.table - can this two-argument function be applied by group more quickly?
  • apply a function to several columns at once with mutate
  • R 'cowplot' neatly produce gridded plot with shared (common) legends and unique legends
  • Repeat R script for many times and save results to text file
  • How to negative lookbehind for special characters
  • data.table inner join produces error when no match is found
  • Create a new column base on existing column, but row above
  • Is there a way to visualize the process of source() in RStudio?
  • google places api consumes 10 request but I am doing only 1
  • Statistical mode of a categorical variable in R (using mlv)
  • Using for-loop to mutate a data.frame in r
  • Make plot with regression line for mixed model
  • Shortcut to select matces cases in R studio
  • vectoriced norm/matrix multiplication
  • Negative log10 transformation in R
  • Plot data with duplicate points
  • Visualizing crosstab tables with a plot in R - changing colours
  • How to manually modify automated numbers and labels in plot
  • How can I follow any redirections of a url in R?
  • Add jitter to box plot using markers in plotly
  • Adding an extra item to the legend
  • ggplot fills in data in the wrong order
  • Convert list to data frame
  • R: filtering by list(s) of strings and returning all results that start with the content of the lists
  • R:How to attach parts of a data frame with different headers and/or an overflowing piece of the dat frame
  • How to use 'par' for manipulating plot margins?
  • Can dplyr::case_when return mix of NAs and non-NAs?
  • Text preprocessing and topic modelling using text2vec package
  • Uploading multiple files in Shiny, process the files, rbind the results and return a download
  • R levelplot: color green-white-red (white on 0) according to one variable, but show the values of another variable
  • Why [i] doesn't point to the starting point in a vector
  • In R after generating a mvrnorm distribution, Y, what does Y[,1] do?
  • expand a data frame to have as many rows as range of two columns in original row
  • Getting started with R and CFA
  • Re order x-axis in ggplot so time goes from 12AM to 11PM in R
  • R - Automatically stack every nth column of a data frame and save them as new objects
  • How to format dplyr output in R into doubles (or other workable format)?
  • Dataframe to matrix conversion using tapply turns zeros to NAs
  • Smallest multiple of 1:20 - How can I make it quicker?
  • How to specify the size of a graph in ggplot2 independent of axis labels
  • How can I find the number of a vector's elements in another vector?
  • ROC curve from train/test set in caret R package
  • Random Forest for a mixture of categorical,numeric and "unwanted" variables which include missing values
  • extract certain data from multiple excel files with R
  • Matrix with counts of wins and losses between methods in R
  • Grouping string variables from a dataframe by best string match to make subsets
  • Reorder does not work after adding second geom_points
  • cover POS data formate to the one can apply Arules (Apriori)
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org