R - Two sets of labels on on axis in a bar plot -



R - Two sets of labels on on axis in a bar plot -

i have dataframe looks this:

id grouping measure1 measure 2 001 59 559 002 44 623 003 b 129 498 004 c 99 504 005 c 78 378

i want produce bar graph has 2 sets of labels on x-axis: 1 identifying each bar id value, labeling each bar grouping belongs to. info set members of same grouping adjacent in dataframe.

the obvious solution of color-coding bars grouping not applicable because using color-coding show measure1 , measure2 (and in cases measure3). if there way show grouping info besides labels, interested hear think 2 sets of labels @ bottom of chart best solution. here's 1 such plot 1 set of labels:

i add together grouping labels underneath "patient id" labels.

if desperate, utilize photoshop or paint add together labels hoping there way add together sec set of labels using r.

try:

mm = melt(ddf, id=c('id', 'group')) ggplot(mm) + geom_bar(aes(x=interaction(id, group), y=value, group=variable, fill=variable), position='dodge', stat='identity')

separator can adjusted:

> with(ddf, interaction(id, group, sep="_")) [1] 1_a 2_a 3_b 4_c 5_c levels: 1_a 2_a 3_a 4_a 5_a 1_b 2_b 3_b 4_b 5_b 1_c 2_c 3_c 4_c 5_c > > with(ddf, interaction(id, group, sep=" ")) [1] 1 2 3 b 4 c 5 c levels: 1 2 3 4 5 1 b 2 b 3 b 4 b 5 b 1 c 2 c 3 c 4 c 5 c

r axis-labels graphing

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -