0
votes

I have 17 vectors containing counts, the length of these vectors range from 2000 to 7000 in length. I searched the internet for how to plot multi-histograms and I read in some places that it's possible to do it by forming a matrix, so I merged the vectors using rbind. I saw methods incorporating ggplot like: ggplot(df, aes(x=count,group=year,fill=as.factor(year)))

But, I think that these examples had equal length, so I'm wondering if it is possible to plot multiple vectors on the same grid in terms of density despite them each having different lengths? And whether I can arbitrarily approximate the x-axis (counts) and y-axis (density)?

1
Could you give some sample data? - psychOle
rps_101_150: 1, 0, 0, 4, 9 rps_151_200: 3, 4, 9, 7, 8 rps_201_250: 4, 6, 14, 7, 6 rps_251_300: 16, 18, 8, 9, 14 rps_301_350: 11, 15, 7, 9, 7 But the lengths of these vectors are unequal i.e. 6598, 6540, 6965, 6964, 6218. edit: I'm terrible at formatting my comments... - Mr Keystrokes

1 Answers

0
votes

Assuming, columns for shorter vectors have NA's in missing rows, following would be one way to do it.

p1 <- ggplot(data = data, aes(x = year1)) + geom_histogram()
p1 <- p1 + geom_histogram(aes(x = year2), col = "red", na.rm=TRUE)
...
p1

Naturally, take care to specify appropriate bin widths and x-axis range. Admit this isn't very elegant.