-2

I have this plot I'm trying to make. I want to make variable a and b non filled and values c and d filled as geom_col. However, there are times a is greater than b and times b is greater than a and I want both the values to show in the plot. Currently a is masking b if if a is higher.

plot <- ggplot(melt_train2, aes(x=f,label=f)) + big_theme + theme2 + theme3

plot + labs(y="abc") +

geom_col(position = "identity",aes(x=d,y=v,width=0.5,

fill=forcats::fct_relevel(variable, c("a", "b","c", "d")),

color=forcats::fct_relevel(variable, c("a", "b","c", "d"))))+

 scale_alpha(c(0,0,1,1),labels=c("a","b","c","d"))  +

 scale_fill_manual(values=c("#000000","#000000","#CD572E","#275636")

,labels=c("a","b","c","d")) + 

scale_color_manual(values=c("#EE82EE","#4782A6","#CD572E","#275636")

,labels=c("a","b","c","d")) + labs(y="abc") +

facet_grid(.~grp2,space="free_x", scales="free_x", 

switch="x",shrink=FALSE)  + 

geom_hline(yintercept=1,color="white",size=2)+

theme(strip.text=element_text(size=18,hjust = 0.5),strip.placement = "outside",
strip.background = element_rect( colour="white"),

panel.spacing=unit(0,"cm")) + coord_cartesian(ylim=c(minval,maxval))

+scale_y_continuous(breaks=seq(minval,maxval,(maxval-minval)/5))
Ark
  • 93
  • 2
  • 6
  • 2
    Please spend some time familiarising yourself with how to provide a [minimal reproducible example/attempt](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), including sample data. As it is, your code is a bit of a mess; please reduce your code to the essential bits, e.g. theming the plot is probably entirely unrelated to your issue. Then clearly state or show (e.g. using a mock-up plot) what you're expected outcome is. – Maurits Evers Mar 07 '18 at 06:21
  • Could you please upload the plot. –  Mar 07 '18 at 06:26

1 Answers1

1

You have set position = "identity" which means you're going to run into problems with one object obscuring another. Try position = "stack", which is, by the way, the default. If you really want position = "identity" try using color alone as your grouping aesthetic, instead of both color and fill. If you set fill = NA inside geom_col, e.g., geom_col(fill = NA, position = "identity", ... That's another option. But really, your best option is probably to just use the default position, i.e., take out position = "identity"

De Novo
  • 7,120
  • 1
  • 23
  • 39