r - how do you create bar charts for two different data columns and one group cloumn -


my data frame:

dput(head(x,3)) structure(list(programs = structure(1:3, .label = c("400.perlbench",  "401.bzip2", "403.gcc", "429.mcf", "445.gobmk", "456.hmmer",  "458.sjeng", "462.libquantum", "464.h264ref", "471.omnetpp",  "473.astar", "483.xalancbmk"), class = "factor"), base_run_time = c(988.746037,  1401.357446, 821.134215), base_rate = c(790.49624, 550.8944,  784.28104), base_geo_mean = c(837.6709, 837.6709, 837.6709),      bench_mark_run_time = c(827.236707, 1329.663649, 818.863431     ), peak_rate = c(944.83232, 580.59792, 786.45592), chip = structure(c(2l,      2l, 2l), .label = c("e5_2660", "e7_4860", "ultrasparc"), class = "factor"),      bench_geo_mean = c(790.4498, 790.4498, 790.4498), percent_difference = c(0.06,      0.06, 0.06)), .names = c("programs", "base_run_time", "base_rate",  "base_geo_mean", "bench_mark_run_time", "peak_rate", "chip",  "bench_geo_mean", "percent_difference"), row.names = c(na, 3l ), class = "data.frame") 

i need create bar chart each group, need have base_run_time , bench_mark_run_time side side, 1 having orange , other having blue color.

i have tried this, gives me stack chart. need bar chart each base_run_time , bench_mark_run_time:

ggplot(x)+geom_bar(data=x, aes(programs, base_run_time, colour="orange", group=chip), stat="identity") + geom_bar(data=x, aes(programs,bench_mark_run_time, colour="blue", fill="green", group=chip), stat="identity") 

any ideas?

you should melt data wide long format , plot data. position="dodge" can set bars side side. melted data frame use value y values , variable fill. scale_fill_manual() can desired colors.

library(reshape2) xx <- melt(x, id = "programs",measure.vars = c("base_run_time", "bench_mark_run_time"))        programs            variable     value 1 400.perlbench       base_run_time  988.7460 2     401.bzip2       base_run_time 1401.3574 3       403.gcc       base_run_time  821.1342 4 400.perlbench bench_mark_run_time  827.2367 5     401.bzip2 bench_mark_run_time 1329.6636 6       403.gcc bench_mark_run_time  818.8634  ggplot(xx,aes(programs,value,fill=variable))+   geom_bar(stat="identity",position="dodge")+   scale_fill_manual(values=c("orange","blue")) 

enter image description here


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -