r - How to make a chart with multi histograms -


i have mess making chart multy histograms in r (try use ggplot2). example of need generated in excel chart (see link):

enter image description here

the initial dataset below:

attribute   dev_share   current_qty_share 1           0,04999641  0,115217086 2           0,050001729 0,076647464 3           0,04999641  0,074048054 4           0,050001729 0,071905297 5           0,049999069 0,067865674 6           0,049999069 0,059962063 7           0,049999069 0,054130954 8           0,049999069 0,052725868 9           0,049999069 0,047421666 10          0,049999069 0,036040466 11          0,049999069 0,033370802 12          0,049999069 0,029085289 13          0,049999069 0,027047913 14          0,04999641  0,034354363 15          0,050001729 0,036567374 16          0,049999069 0,039728818 17          0,049999069 0,042222847 18          0,049999069 0,036532247 19          0,049999069 0,02511592 20          0,050017684 0,040009836 

for each attribute (#1,2,3...) correspond 2 variables ('dev_share' - blue color , 'current_qty_share' - green, yellow, red colors.

two dashed lines mean cut-offs: first cut-off corresponds 17th attribute , second 1 - 10th attribute. cutt-offs landmarks distinguish colors per attribute 'current_qty_share' variable: 17-20 - green, 10-16 - yellow, 1-9 - red. blue color same attributes of 'dev_share'.

x-axis contains attribute values, y-axis cintains values of 'dev_share' , 'current_qty_share'.

it grateful if make hint ot example how make chart in excel template (see link).

here started. first, had replace "," "." in data frame. if want show both columns, need convert data frame wide long. added way color differently bars, can change wish.

library(ggplot2) library(reshape2) data_wide <- read.table(text=" attribute   dev_share   current_qty_share 1           0.04999641  0.115217086 2           0.050001729 0.076647464 3           0.04999641  0.074048054 4           0.050001729 0.071905297 5           0.049999069 0.067865674 6           0.049999069 0.059962063 7           0.049999069 0.054130954 8           0.049999069 0.052725868 9           0.049999069 0.047421666 10          0.049999069 0.036040466 11          0.049999069 0.033370802 12          0.049999069 0.029085289 13          0.049999069 0.027047913 14          0.04999641  0.034354363 15          0.050001729 0.036567374 16          0.049999069 0.039728818 17          0.049999069 0.042222847 18          0.049999069 0.036532247 19          0.049999069 0.02511592 20          0.050017684 0.040009836",   header = true)  data_long <- melt(data_wide, id.vars=c("attribute")) data_long$color <-    with(data_long,        ifelse(variable == "current_qty_share", "darkblue",           ifelse(variable == "dev_share" & attribute >=1 & attribute <8,                  "darkred",                  ifelse(variable == "dev_share" & attribute >=8 & attribute <=17,                         "green",                              "yellow")))  ggplot(data=data_long, aes(x=as.factor(attribute), y=value, group=variable, fill=color)) +  geom_bar(stat='identity', position='dodge') +  theme_bw() +  geom_vline(xintercept=10, linetype = "longdash") +  geom_vline(xintercept=17, linetype = "longdash") +  xlab("attribute") +  ylab("value") +  scale_fill_manual(values=c("darkblue", "darkred", "green", "yellow")) 

enter image description here


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -