dendextend | Extending R 's Dendrogram Functionality | Build Tool library
kandi X-RAY | dendextend Summary
kandi X-RAY | dendextend Summary
Class "dendrogram" provides general functions for handling tree-like structures in R. It is intended as a replacement for similar functions in hierarchical clustering and classification/regression trees, such that all of these can use the same engine for plotting or cutting trees. However, many basic features are still missing from the dendrogram class. This package aims at filling in some gaps.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of dendextend
dendextend Key Features
dendextend Examples and Code Snippets
Community Discussions
Trending Discussions on dendextend
QUESTION
I want to rotate the order of several groups in a dendrogram and managed to do it with dendextend. However, when I try to save the plot with ggsave I end up with the original dendrogram, unrotated. Is there a way to save the rotated dendrogram with ggplot2? My code is as follows:
...ANSWER
Answered 2021-May-22 at 17:04Several points:
- I don't think there is a need to use the
dendroextras
package. Thedendextend
package includes all the functions you need (with a more consistent API). - No need for
ggplot2
orggsave
, since the plot you're creating is not a ggplot2 plot, but rather an R base Graphics plot. Hence, you can save your plot using something like png("file_loc.png"); plotting_functions(); dev.off() - You need to save the rotation into the dendrogram
Like this:
QUESTION
I was able to create a stacked bar chart like this:
...ANSWER
Answered 2021-May-12 at 17:22I figured it out by modifying the code of the circos.barplot
function.
The labels are drawn in a second loop after the rectangles so that the rectangles are not drawn over the labels.
QUESTION
I'd like to create a hierarchical clustering tree of a relatively large dataset (>3000 obs). Unfortunately, by including so many labels at the terminal nodes, the tree looks very cluttered and contains lots of unnecessary information. So to reduce the clutter, I'd like to just label one observation of interest. I have removed all of the labels but I don't know how to retrieve and add the label that I'm interested in.
For this MWE, let's assume, I'd like to add the letter k to my dendrogram.
...ANSWER
Answered 2020-Dec-15 at 21:42You can specify the labels set
function. If you only want to show one, make the others be the null string.
QUESTION
I am working with ecological data (the percentage abundance of different diatom species present at different depths in a sediment core) and want to plot the results alongside a dendrogram representing the results of a hierarchical cluster analysis (CONISS) that I will use to split the core into ecological zones.
This is an example of the type of thing I am trying to achieve:
I have successfully run the cluster analysis but am struggling to plot the dendrogram the way I would like to. Whenever I plot the dendrogram, it plots the leaves of the dendrogram in sequential order (as shown here). However, I need the leaves to plot by depth from the top of the sediment core so that there is a leaf present at each depth of the core that I have examined and so that there are gaps in the dendrogram where I have missing samples (as shown here). (Note there is no y-axis shown here as the dendrogram will join onto the rest of the diagram, which already contains the y-axis.)
I managed to create the latter plot through the rioja package using plot.chclust
and providing the depths for the leaves to the xvar
argument. However, I have constructed the rest of my diagram (the species abundance data, PCA results etc.) with ggplot (and the help of the tidypaleo package) and then combined the various aspects of it using cowplot. I need to be able to create the dendrogram through ggplot in order to add it to my main diagram. I have investigated both the ggdendro and dendextend packages but can't find a way to plot the dendrogram according to depth using these. Is this possible? Do these packages have a function to do this that I am not aware of? I started looking into the source code for these packages as well as for as.dendrogram
to see if I could figure out a way of modifying the functions to plot the leaves by depth but it is beyond my skill level. I was wondering if anyone has a solution to enable me to plot my dendrogram by depth in my sediment core rather than in sequential order?
This is the data that I have used to calculate the distance matrix in the code below. (Apologies for the very long dput!)
My code to plot the dendrograms ...ANSWER
Answered 2020-Dec-08 at 21:43The actual depths are mapped to the x values in ddata$labels
, so you can reverse-map the x values to actual depths. A handy way to do this is with approxfun
:
QUESTION
I have a heatmap I made through R with pheatmap package :
The problem is that it's a bit unlisible ( I 've exported it on a pdf but we need to zoom to see the whole picture) plus I only want to keep the dendogram and tidy the y axis with the group column to have something like this :
Here is a look of my datas :
...ANSWER
Answered 2020-Aug-12 at 08:00The pheatmap
function returns the row and column dendrograms, which can be plotted separately.
See the following example.
QUESTION
Upon opening a project on rstudio i have the following Warning:
...ANSWER
Answered 2020-Sep-15 at 22:47I think this is ultimately a small bug in renv
. Here's my guess at what's happening:
While this project has been initialized as an
renv
project, it does not have a lockfile for some reason. (Perhapsrenv::activate()
was called to initializerenv
without explicitly creating a lockfile?)The project has an
renv
autoloader; this is from a script atrenv/activate.R
. That script is configured to loadrenv 0.11.0
.When the project is loaded,
renv
finds thatrenv 0.12.0
is installed in the project library, not the expected version0.11.0
. This causes the warning to be emitted. (Perhapsrenv
was updated in that project previously?)
So, ultimately, the warning is misleading here -- the request for renv 0.11.0
comes directly from the autoloader, not from the lockfile (which does not exist). As for why the lockfile does not exist, I'm not sure -- but it most likely implies the project was initialized via renv::activate()
, and not by renv::init()
.
All that said -- you can safely re-generate the lockfile via renv::snapshot()
.
QUESTION
I have the following code:
...ANSWER
Answered 2020-Aug-12 at 06:25Maybe this is what you are looking for.
QUESTION
This is a similar question but not quite the same since I would like to do this with dendextend. My issue is that some of the names of my labels are quite long and I would like to just remove them. I had tried a few techniques already.
- I tried changing cex = 0
- I tried changing the color to white but all this does is hide the labels and when the names are long is still an issue.
- I tried plotting labels =F , but this does not work as well. Is there anyway to completely eliminate the labels? Here is an example code.
ANSWER
Answered 2020-Aug-05 at 20:12You can use dendrapply to change or remove the label attribute of the leaf nodes:
QUESTION
I wish to visualize how well a clustering algorithm is doing (with certain distance metric). I have samples and their corresponding classes. To visualize, I cluster and I wish to color the branches of a dendrogram by the items in the cluster. The color will be the color most items in the hierarchical cluster correspond to (given by the data\classes).
Example: If my clustering algorithm chose indexes 1,21,24 to be a certain cluster (at a certain level) and I have a csv file containing a class number in each row corresponding to lets say 1,2,1. I want this edge to be coloured 1.
Example Code:
...ANSWER
Answered 2017-Aug-01 at 11:00there are suspicions that misunderstood the question however I'll try to answer: from my previous objectives were rewritten by the example of iris
QUESTION
The following code produces the shown plot.
...ANSWER
Answered 2020-Feb-17 at 17:57The issue with your color pattern is that your vales are not sorted in the same order for each plot. On the right plot, hclust
will order each id in function of their distance and on the left plot they are sorted by their label id.
To get the same order, you need to attribute the order of hclust
to your dataframe. You can find this order in the variable order
from your hclust
object:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install dendextend
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page