Density plot keeps plotting multiple distributions. How to plot one distribution at a time?

Hi,

I'm using the tidyLPA package to run some latent profile analyses and I want to check the distributions of each of my profiles separately.

The package allows me to use the "plot_density" function to create density plots. When using the following command it creates plots for all six of my profiles.

plot_density(m1.1)

I tried using the following command to plot only one type of profile in this case profile 2. However it would then plot all the profiles below it, so in this case profiles/classes 1 and 2 would be plotted and not just profile 2 as I wanted (thus if I entered "class_6" it would show plots for all 6 classes and not only class 6 etc).

plot_density(m1.1$model_1_class_2)

This is quite annoying as there is just too much on the screen for me to be able to inspect the distribution of each profile properly. Does anyone know how I could make it only show one profile at a time? I can't seem to find anything from the author showing how to do this as all the info on tidyLPA's plot functions only talk about restricting variables but not profiles.

Thanks
L

PS: The following other packages are loaded.

library(tidyverse)
library(here)
library(dplyr)
library(kableExtra)
library(tidyLPA)
library(mclust)
library(rio)
library(foreign)
library(openxlsx)

The bottommost example in the ?plot_density help, is of this type I believe.
Use square brackets to pull out only the profile of interest.

plot_density(m1.1[[2]])

No luck, unfortunately, still did the same thing as the previous command I tried. Are you familiar with tidyLPA? Perhaps there's a way to place only one profile from a solution into an object (maybe using the <- function) and then only analyse that?

Unfortunately, I wouldn't know where to start with that! Still learning the ropes!

Thanks for your help regardless.

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Hey, sorry it took so long to get back to you work has been a bit snowed under last couple of days. Thanks for taking the time. I tried my best to make a reprex though I couldn't get everything from the instructions to work 100%. I hope this is sufficient though

```{r setup, include=FALSE}
#packages needed: 
library(tidyLPA)
library(mclust)
library(rio)
library(dplyr)
library(openxlsx)

#example data, similar to my real data as it has several personality traits and emotion regulation strategies. 

trait_one <- c(10,15,20,8,15,12,14,15,18,9,7,12,12,7,21)
trait_two <- c(9,7,12,22,23,4,3,8,9,2,8,22,8,4,22)
trait_three <-c(8,3,22,12,7,4,4,8,3,12,11,21,6,5,20)
trait_four <- c(14,14,2,9,4,5,19,24,25,12,14,8,9,1,12)
strat_1 <- c(4,5,2,8,10,8,2,6,4,3,8,9,3,9,5)
strat_2 <- c(1,5,4,2,5,8,1,8,9,7,3,3,8,3,9)
strat_3 <- c(9,6,2,6,1,8,1,6,6,7,5,3,2,4,6)
strat_4 <- c(9,1,6,3,2,10,4,10,3,5,3,3,7,3,2)
strat_5 <- c(10,6,3,4,8,9,3,2,7,2,4,5,4,1,8)

df <- data.frame(trait_one,trait_two,trait_three,trait_four,strat_1,strat_2,strat_3,strat_4,strat_5)

df

#below command will run LPA. This will force a run of three profile solution, which will be enough to test out getting separate density plots.

LPA_analysis <- df[, ] %>%
  select(trait_one,trait_two,trait_three,trait_four,strat_1,strat_2,strat_3,strat_4,strat_5) %>% 
  single_imputation() %>%
  estimate_profiles(3,
                    variances = c("equal"),
                    covariances = c("zero"))


#This will make density plots. In this example, I want to generate three separate plots, one for each profile/class, showing the distribution of all univariate variables in said profile. However, this command is generating all profiles (1-3) at the same time. 

plot_density(LPA_analysis$model_1_class_3)

If you need anything else please let me know and thanks again for your help.
L

Also here are the install.packages commands ready to go for you if that makes things easier

install.packages("tidyLPA")
install.packages("mclust")
install.packages("rio")
install.packages("dplyr")
install.packages("openxlsx")

I'm going to throw my hands up and say that tidyLPA just wasnt designed to produce the broken out view that you would like. Perhaps make a feature request via New Issue for it over at their github : Issues · data-edu/tidyLPA (github.com)

Thats ok! Thanks, heaps for your help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.