0

I did the following barchart by using:

ggplot(yearplot,aes(x=reorder(vE,release.year), y=difference,fill=PAR,label=signif.))  + 
  geom_bar(stat='identity',position = "dodge",  size=3 ,alpha=1)  +
  geom_text(aes(x = vE, y = difference+0.03 , label = format(signif., nsmall = 0, scientific = FALSE)), 
  color="black",size=6) +
  xlab("Genotypen")+
  ylab("Differenz")+
  theme_bw()+
  ylim(-0.2,0.2)+
  facet_wrap(~number,labeller = labeller(number=date.wrap),nrow=1)+
  coord_flip()+
  scale_fill_gradient2(name="PAR \n[mol/m² s]",low="darkblue",mid = "orange1",high = "orangered4",limits=c(1200, 2100),midpoint = 1200)+
  theme(legend.position="top")+
  theme(legend.key.size = unit(3,"line"),
        legend.title = element_text(size = 16,face="bold"),
        legend.text = element_text(size = 14))+
  theme(axis.text=element_text(size=14,face="bold"),
        axis.title=element_text(size=16,face="bold"),
        strip.text = element_text(size=16,face="bold"))

enter image description here

I would like to add temperature values as gradient filled plot panels, similar to the PAR values. So for example the plot panel of june 1 is light green and june 6 is dark green and the rest between. In the data frame is one temperature value for each day. Is there any possibilty to do that?

tjebo
  • 21,977
  • 7
  • 58
  • 94
David
  • 39
  • 6
  • 2
    Please provide a reproducible example of your data (see: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Otherwise, it will be really complicated to help you address this problem – dc37 Jan 02 '20 at 22:37

1 Answers1

0

Your question contains a lot of code, but it is nonetheless not reproducible. A shame! It's in general an interesting question. Although I personally think that 'less is more' and one should try not to put too much information in one's graphs, here is one solution.

  • You want plot panels filled? Make large rectangles underneath your bars.
  • You want two fills? Use ggnewscale.

Voilà!

library(tidyverse)
library(ggnewscale)

mtc <- tibble::rownames_to_column(mtcars, 'model')

rect_df <- data.frame(xmin = -Inf, xmax = +Inf, ymin = -Inf, ymax = +Inf, cyl = unique(mtc$cyl))

ggplot() +
  geom_rect(data = rect_df, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, fill = cyl)) +
  facet_grid(~cyl) +
  scale_fill_gradient(low="lightgreen",high = "darkgreen") +
  ggnewscale::new_scale_fill() +
  geom_col(data = mtc, aes(x = model, y = gear, fill = disp)) +
  scale_fill_gradient2(low="darkblue",mid = "orange1",high = "orangered4",limits=c(min(mtc$disp),max(mtc$disp)),midpoint = mean(mtc$disp)) +
  coord_flip()

Created on 2020-01-03 by the reprex package (v0.3.0)

tjebo
  • 21,977
  • 7
  • 58
  • 94