The labels of my dendrogram contain too much unnecessary information, so I want to change them into shorter versions. Additionally, all the labels are colored by their group affiliation.
Now I want to have the labels without the first three and the last two numbers: 012.4A16 -> 4A. But without changing anything else (color, group affiliation) in the dendrogram.
I searched the web for instructions on how to do it, but or the code was too complex for me to understand it, or it changed my group-colors.
Could anyone of you please tell me if it is possible to make these changes and if so, how?
Hi,
A simple way to do this could be to change the names in your original dataset rather than trying to rename the labels. Based on your screenshot, it looks like the two digits that you want to keep are enough to uniquely identify each observation, is that correct?
In this case and if your original data has a column that contains the names, you could for example use tidyr::separate to create a column with the short names in your original data.
The functions works like this:
suppressPackageStartupMessages(
library(tidyverse)
)
#sample data
mydf<-data.frame(name=c("012.4C16","002.1B16","010.4A16","006.2C16"))
#split up the names after the forth and sixth digit
mydf%>%
separate(name,into=c(NA,"shortNname",NA),sep=c(4,6),remove = FALSE)
#> name shortNname
#> 1 012.4C16 4C
#> 2 002.1B16 1B
#> 3 010.4A16 4A
#> 4 006.2C16 2C