Ggplot line size base on color

Hi all,

I am using a geom_density() in a ggplot, with an aes(color = var2) to compare multiple overlaying density plots. I have figured out how to use scale_color_manual to manually change the colors to ones that I want - but there is a way to manually change the alpha or size, but have them differ based on which group?

i.e. I know how to make var2=1 as black and var1 = 2 as green, but lets say I want var1=1 density as thickness 2 and var1 = 2 density as thickness 0.5? (or alternatively as alpha = 1 and alpha = 0.5). Is there a way to do that?

Thanks everyone!

PS Would it matter if, instead of geom_density, I used ggridges::geom_density_ridges?

You can probably use alpha = the_variable_you_want_to_control_alpha and size = the_variable_you_want_to_control_alpha inside your aes() call to map var2 to the alpha and size attributes, then use scale_alpha_manual() and scale_size_manual() (in the same way as you are already using scale_colour_manual()).

scale_alpha_manual and scale_size_manual should provide you with the equivalent.