0

I am trying to make a stacked bar with the beginning and ending labels for each stacked element. my code is this:

ggplot(chr2007816root, 
 aes(fill=factor(Feature,levels = c("tnt1","ex6", "int5", "ex5", "int4", 
          "ex4", "int3", "ex3", "int2", "ex2", "int1", "ex1")),y=Name, x=Length) )  + 
 
geom_bar(colour=factor(chr2007816root$Name, 
          levels=c("Type6")),width = 0.3, position ="stack",  stat = "identity") + 

ggtitle("chr2_007816_root") +

theme(plot.title = element_text(hjust = 0.5)) + 

geom_text(aes(label=factor(Feature, levels= c("ex2","int2","ex1", 
          "int1","ex3","ex4", "int4", "ex5", "int5", "ex6", "tnt1"))),
           cex=2, position = position_stack(vjust = 0.5), color="white")  +

geom_text(aes(label= Count), angle= -90, cex=3 ,vjust=1, hjust=-1,
 position = "stack") + 

geom_text(aes(label=Start),angle= -90, vjust=0, hjust=1, nudge_x =10) + 

scale_fill_manual(values = c("darkslategray", "pink", "darkslategray", 
"pink", "darkslategray"))  +

    theme(axis.line=element_blank(),
          axis.ticks=element_blank(),
          axis.text.x=element_blank(),
          axis.title.x=element_blank(),
          axis.title.y=element_blank(),
          legend.position="none",
          panel.background=element_blank(),
          panel.border=element_blank(),
          panel.grid.major=element_blank(),
          panel.grid.minor=element_blank(),
          plot.background=element_blank()) 

this works fine for only labeling the endpoint. but I can't for the life of me label the beginning number at the start of the stack with hjust or vjust. can someone help? You can understand from the picture, I am trying to add a beginning value as well, thank you

graph

Quinten
  • 35,235
  • 5
  • 20
  • 53
selmanurk
  • 1
  • 2

0 Answers0