0

I am trying to plot 5 variables. however, I only see one colour. I am not really sure how can I display different colour for each variable

my data looks like

> data
    Lead_1 Lead_2 Lead_3 Lead_4 Lead_5
1      138    135    128    125    130
2      126    130    133    131    128
3      120    121    126    130    129
4      129    126    121    115    110
5      142    153    160    167    179
6      305    299    294    291    283



dim(data)
[1] 8517    5

enter image description here

enter image description here

data <- read.table("5leads.csv", header=TRUE, sep=",")
data
dat <- stack(data)
ggplot(dat, aes(x = values, fill = ind)) + geom_density(alpha = 0.25)
EA90
  • 23
  • 5
  • Since you haven't provided a [reproducible sample](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data, I can only provide my best guess. Since you're using `fill` instead of `color` and your `alpha` isn't < 1, your dataset with the largest values may be eclipsing the others – Punintended Oct 13 '20 at 21:20
  • Please make your example reproducible, either by including data with `dput()`, or by reproducing your problem with a built in dataset. [This question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) shows how you can include data in your R questions on stack overflow. – Jan Boyer Oct 13 '20 at 22:26

2 Answers2

0

Try this approach using both color and fill as mentioned in the comments by @Punintended:

library(ggplot2)
#Code
dat <- stack(data)
ggplot(dat, aes(x = values, fill = ind,color=ind)) + geom_density(alpha = 0.15)

Output:

enter image description here

Or this:

#Code 2
dat <- stack(data)
ggplot(dat, aes(x = values, fill = ind,color=ind)) + geom_density(alpha = 1.5)

Output:

enter image description here

Duck
  • 39,058
  • 13
  • 42
  • 84
  • Thanks a lot this really help . It wasn't all in one colour but vales were very close so looked like all in one colour since I had more than 8000 rows – EA90 Oct 13 '20 at 21:57
  • @EA90 I hope it helped you! – Duck Oct 13 '20 at 21:59
0

I tried to use

ggplot(dat, aes(x = values, fill = ind,color=ind)) + geom_density(alpha = 0.15)

and this is what I am getting

enter image description here

EA90
  • 23
  • 5