0

I'm trying to make a plot like this:

Profile Plot by Phenotype

When I attempt with x=variable, y=value, and group=[an identified cluster], I get the following plot.

Profile Plot of Variables by Cluster

I start with scaled model indicators, which are columns including age, vital signs, laboratory values, and medications. I also have id and cluster as variables.

melt_mod_indic_z<-melt(mod_indic_z, id.vars=c('cluster'))

ggplot(melt_mod_indic_z) +
geom_line(aes(variable, value, group = cluster,
color = cluster))

Is there a way to correct this? Thanks in advance!

Quinten
  • 35,235
  • 5
  • 20
  • 53
kp_phd
  • 1
  • Could you please share some reproducible data using `dput`? So we can help you better. – Quinten Jul 28 '22 at 18:36
  • 2
    It looks like there are multiple values for each cluster at each point on the y axis. Perhaps you want `geom_smooth` instead of `geom_line`? Or summarize the data into means at each variable / cluster combination? – Allan Cameron Jul 28 '22 at 19:55
  • 1
    Is there some reason that you have a bunch of categorical variables (presumably) on the x-axis but a continuous line plotting their values? – socialscientist Jul 28 '22 at 20:16
  • @socialscientist great question! Yes, this is a profile plot so it’s meant to display a visual of standardized values for variables, hence defining the profile for different latent classes. I’ve made this plot in Python before but R is new to me. – kp_phd Jul 29 '22 at 01:21
  • 2
    In addition to the point @AllanCameron makes above, you'll probably want to arrange the `x` axis by `y` value so you can observe a trend like in your example plot. For example, something like `aes(reorder(variable, value), value)` – Dan Adams Jul 29 '22 at 02:08

0 Answers0