This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag(): dplyr, stats
library(magrittr)
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
abc<-data_frame(new_value=as.factor(c(rep("s1",4),"s2","s2")),interval=c(43,24,69,104,19,16),value=c("A","B","C","B","C","D"),seq=as.factor(c(1,2,3,4,1,2)))
ggplot(abc,aes(x=seq,y=interval,fill=seq))+geom_bar(stat="identity")+facet_grid(new_value~.)+coord_flip()
library(forcats)
abc$new_value<-fct_relevel(abc$new_value,c("s2","s1"))
abc$seq<-abc$seq%>%fct_rev()
ggplot(abc,aes(x=new_value,y=interval,group=interaction(value,seq),fill=value,label=value))+geom_bar(stat="identity",width=0.5)+coord_flip()+geom_text(size=5,position=position_stack(vjust=0.5))+theme_bw()
#+scale_fill_manual(values = c( "red", "blue", "green","black"))
abc
## # A tibble: 6 × 4
## new_value interval value seq
## <fctr> <dbl> <chr> <fctr>
## 1 s1 43 A 1
## 2 s1 24 B 2
## 3 s1 69 C 3
## 4 s1 104 B 4
## 5 s2 19 C 1
## 6 s2 16 D 2