0

i have two type of parameters and one response for one chemical compound:

plotted

The code used to generated this picture was

    for (i in levels(data$ProteinName))
    {
      temp <- subset(data, data$ProteinName == i)
            plot <- ggplot(data = temp, aes(x= temp$id, y = temp$Matrix))+
              geom_tile( aes( fill= temp$TotalArea))+
              labs(title= i, x = NULL, y = NULL, fill = "Average Total Area")+
              geom_text(aes(label=round(TotalArea, digits = 0)), color = "White")+
              scale_fill_gradientn (colors=c(low = "blue4", mid="gold", high = "red"),
              na.value = "violetred")+
              theme_bw()
       print(plot)
    }

but this is one of 12 plots so for my report i had to take it into a facet but i haven't found anny method to create a free scale for the "z axis" scale the current code is

    temp <- data
            plot <- ggplot(data = temp, aes(x= temp$id, y = temp$Matrix))+
              facet_wrap(~temp$ProteinName, scale = "free")+
              geom_tile( aes( fill= temp$TotalArea))+
              labs(title= i, x = NULL, y = NULL, fill = "Average Total Area")+
              geom_text(aes(label=round(TotalArea, digits = 0)), color = "White")+
              scale_fill_gradientn (colors=c(low = "blue4", mid="gold", high = "red"), 
              na.value = "violetred")+
              theme_bw()
       print(plot)

and gives the follow:

result

but here is the color of the tiles (z axis) not free did any body know how to create a free z axis? you can see ad the PE facet that it is only blue but within this facet there is a quite large difference with the observed concentration.

The goal is that te readers can see what is the larges respons (red) and the lowest (blue).

Hopefully you can help me.

Sixiang.Hu
  • 1,009
  • 10
  • 21
  • 2
    This question is not reproducible without the data. Please could you add that using `dput`. TY – dww Mar 14 '18 at 16:39
  • `?scale_fill_gradientn` - one option to set the scale manually using `values` argument. But I guess, you might want to have a look at: https://stackoverflow.com/questions/14840542/place-a-legend-for-each-facet-wrap-grid-in-ggplot2 – tjebo Mar 14 '18 at 19:47

1 Answers1

0

Thanks for the answers, with the help of the post: Place a legend for each facet_wrap grid in ggplot2 it was verry easy done, the old script was:

for (i in levels(data$ProteinName))
{
  temp <- subset(data, data$ProteinName == i)
        plot <- ggplot(data = temp, aes(x= temp$id, y = temp$Matrix))+
          geom_tile( aes( fill= temp$TotalArea))+
          labs(title= i, x = NULL, y = NULL, fill = "Average Total Area")+
          geom_text(aes(label=round(TotalArea, digits = 0)), color = "White")+
          scale_fill_gradientn (colors=c(low = "blue4", mid="gold", high = "red"),
          na.value = "violetred")+
          theme_bw()
   print(plot)
}

with result: old plot

after that we updated the script with the fucntion grid.arrange(grobs = list_of_plots) from the gridextra package there for i had to make a list in the loop, this was done with: plot_v[[i]] <- plot, plot_v is the name of the list of plots.

this list was then added to the grid arrange

so the new script is now

    require(gridExtra)
    require(ggplot2)    
plot_v <- list()
        for (i in levels(data$ProteinName))
        {
          temp <- subset(data, data$ProteinName == i)
                plot <- ggplot(data = temp, aes(x= temp$id, y = temp$Matrix))+
                  geom_tile( aes( fill= temp$TotalArea))+
                  labs(title= i, x = NULL, y = NULL, fill = "Average Total Area")+
                  geom_text(aes(label=round(TotalArea, digits = 0)), color = "White", size= 2.5)+
                  scale_fill_gradientn (colors=c(low = "blue4", mid="gold", high = "red"),
                     na.value = "violetred")+
                  theme_bw()+
                  guides(fill = "none")
           print(plot)
           assign(paste("plot", i, sep="_"), plot)
           plot_v[[i]] <-  plot
        }
        grid.arrange(grobs = plot_v)

this gives as result new plot

I want to thank you for your help