Closed hichew22 closed 10 months ago
Hi @hichew22, thanks for the suggestion. It's a useful feature to have, especially when comparing similar cluster solutions.
I'll start with adding an argument to plotClusterTrajectories for specifying which clusters to plot, and the ordering.
Ultimately, having a wrapper lcModel
class for which you can specify the ordering logic would be best. But that'll take some more effort.
plotClusterTrajectories
now has a clusterOrder
argument allowing you to specify which clusters to plot, and the order thereof. Either by name or index
Awesome, thanks, Niek! Do you have an example, and does this also allow ordering clusters from most to least frequent?
You're welcome!
data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData, nClusters = 3)
# change cluster order
plotClusterTrajectories(model, clusterOrder = c('B', 'C', 'A'))
# show only specific clusters
plotClusterTrajectories(model, clusterOrder = c('B', 'C'))
It's intended as a quick way to set a custom order, but to dynamically order by cluster size, you can use:
plotClusterTrajectories(model, clusterOrder = order(-clusterSizes(model)))
In the future I intend to add some lcModel
wrapper classes that would automatically relabel clusters based on some criterion, so the ordening would then be handled during the latrend fitting procedure.
I tried doing that for a 4-cluster DTW model as such: plotClusterTrajectories(dtw_model_4, clusterOrder = order(-clusterSizes(dtw_model_4)))
However, the clusters do not appear ordered. I did make sure to download the most recent installation of latrend. Could you help me with this?
Did you install the latest commit (not release)?
remotes::install_github('philips-software/latrend')
Yes, I just did but seems like the function does not work.
─ preparing ‘latrend’: (555ms) ✔ checking DESCRIPTION meta-information ... ─ installing the package to process help pages (811ms) Loading required namespace: latrend ─ saving partial Rd database (3.1s) ─ checking for LF line-endings in source and make files and shell scripts (335ms) ─ checking for empty or unneeded directories ─ building ‘latrend_1.5.1.tar.gz’
I can't spot any issues in the source code. Could you let me know what the output is of:
latrend:::make.orderedClusterNames(clusterNames(dtw_model_4), order(-clusterSizes(dtw_model_4)))
I just tried re-running it and it works now! Perhaps I had to restart my R session. Thank you so much!
Hello Niek,
I am using the dtw method in latrend to plot some clusters like so:
plotClusterTrajectories(dtw_model_2)
or
plot(dtw_model_2)
Is there a way within plotClusterTrajectories() where I can specify that the cluster with more values is always listed as cluster "A" (highest frequency to lowest frequency)?
Or would I need to reorder them manually, something like:
?
Thank you!