ggdendro | Tools to extract dendrogram plot data for use with 'ggplot2 | Data Visualization library
kandi X-RAY | ggdendro Summary
kandi X-RAY | ggdendro Summary
Provides functions for creating dendrograms and tree plots using ggplot2.
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 ggdendro
ggdendro Key Features
ggdendro Examples and Code Snippets
Community Discussions
Trending Discussions on ggdendro
QUESTION
I'm new to Rshiny. I have been tasked with the following:
Write a shiny app which uses a Navbar, with headings "Data Exploration" and "Classification tools", so that, within the Data Exploration tab, the user can:
choose any variable and see summary statistics of it,
use a select input to see summary statistics of a variable by Rate category.
see a plot of the beertax variable by Rate group when the app is first opened.
Choose any variable and visualise its relationship with the Rate variable. Different plots should appear depending on whether the selected variable is continuous or categorical.
within the Classification tools tab, the user can:
use a slider input to select from (0.4, 0.5, 0.6, 0.7, 0.8), the proportion of data used for the training data set (we will not be using the test data here, so you should use the complement proportion for the validation data set.)
view a classification tree for the training data, and use the radio buttons to either "view pruned tree" or "view unpruned tree". Where, for the pruned tree, pruning should be done using the cp value that corresponds with the smallest xerror.
see both the correct- and miss- classification rates (using the validation data) for the pruned classification tree and one of LDA or QDA, these results should be presented in a table. The "best" classification method, i.e. that with the lowest missclassification rate, should be highlighted and there should be a note to inform the user of what the highlighting means.
make a prediction of the Rate status (i.e. above or below the US average) of an average unseen state, using the "best" classification method, with a user defined set of observed variable values (i.e. input options will be needed to allow the user to input their desired observed values). The default user defined values, that appear when the app is opened, should be the mean of the continuous variables and the mode of the categorical variables. There should also be a warning which alerts the user when they are extrapolating.
Currently, I've pretty much completed up to step 3 of the Classification tools tab. However, I'm experiencing various errors that I need help with. I'll talk about them in order:
When I run the app after opening Rstudio, my first tab 'Data Exploration' runs fine. However, whenever I reload the app, the summary table fails and I get the error 'unused argument (input$variable)'. I'm not sure why this is happening.
When I run the app, there appears an error on the second tab 'Classification tools' which reads 'non-numeric argument to binary operator'. I investigated what this meant and I think I understand it but i'm just not sure how this error applies to my code. Instead of this error, my aim is to generate a table which includes the classification rate and missclassification rate of the CART model and eventually the LDA model too (dependent on the training data proportion input).
Following from issue 2, I investigated my code and realised that I think the previous error occurs due to the line lda.pred <- predict(lda.model, newdata = valid.data[,-6]) and so I removed the code to see what would happen and then I end up with a new error 'unused argument (pred == valid.label)'. Again, I don't understand why this is happening.
Here is my code:
...ANSWER
Answered 2020-Dec-23 at 13:44The use of req()
and as.numeric()
should fix the first two issues. You should be able to fix the last one after this.
EDIT
Changing select(input$variable)
to dplyr::select(input$variable)
should eliminate your first error. There are 4 other packages with the same function select()
, in your list of packages; hence you need to specify which package you intend to use it from or load dplyr
last.
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 massive dendrogram with hundreds of names on it, that I'd like to be make interactive so that users can draw a box and "zoom in" on the names and part of the tree of interest. The original code for creating it is borrowed from here. Pictured here:
I turned it into a shiny app and borrowed some code from here in order to make it zoomable. And it KINDA works. It runs, the two graphs show up, and nothing gives me an error. But it doesn't work as intended. (I'll post code below). What I mean is that if I were to simply render my plot outside of shiny, all the names and everything are included. But when it renders in shiny, I can't draw my box over the names, only the lines of the dendrogram (hope that makes sense), and the "zoomed" graph is turned sideways (something to do with the coord_cartesian? What would I use instead) and looks very weird when it "zooms". Lastly I can't see both graphs at the same time and have to use a scroll bar to get to them, pictured:
Help! Code below (its from an r markdown document if that matters, sorry I couldn't include the actual data, has real names.
...ANSWER
Answered 2020-Aug-08 at 16:31The tool I'd suggest using is dendextend+ggplot+plotly.
Example:
QUESTION
I'm having trouble right aligning horizontal y axis titles for multiple plots in R ggplot2. I have a main plot which is a dendrogram with leaf labels created using the ggdendro package, and I have multiple color bars below the main plot with titles to the left. If I use grid.arrange to place the plots on the same page, I'm able to get good vertical spacing between the plots, but I'm not able to right-align the y axis titles for the color bars consistently. If I use plot_grid, I can right-align the y axis titles consistently, but I'm having trouble getting appropriate vertical spacing between plots. Any help would be appreciated!
Update: Two suggested solutions work equally well so I'm accepting the first one as the answer. Using ggarrange
from the egg package and using plot_grid
with align = "v"
instead of align = "hv"
both fixed my problem.
Create main plot and color bars:
...ANSWER
Answered 2020-Aug-06 at 08:56egg
package will get the job done
QUESTION
I am trying to apply dendextend in order to color the ggdendro labels. I get this error:
...ANSWER
Answered 2019-Feb-11 at 08:46Seems you were confusing dendrogram with dendrogram data. This will work:
QUESTION
How can I change the labels of the dendrogram to them matching name in the list? At the moment I only get the list number.
Code:
...ANSWER
Answered 2019-Feb-08 at 13:50You are loosing your labels right after dtw_distmat
function:
QUESTION
My task is to create a dendrogram, but the leaf nodes shows blunt edges. How would I extend the length of the leaf node, and add node labels?
Please see the current and expected images below.
Data:
...ANSWER
Answered 2018-Apr-26 at 02:48There are a couple of ways to do this, the simplest is probably to apply a function recursively over the nodes of the dendrogram using dendrapply
.
If you insert a new line to assign the dendrogram object:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ggdendro
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