r - Different legends and fill colours for facetted ggplot? -


Sorry for not including any example data for my problem I'm not easily the way to generate an example size file Hopefully, experienced users of ggplot can see what I want to do with the details below. I have found:

  • plot , var1 , var2 data.frame x> var3 , var4 , ...)

    with information about code>, Li>
  • Import a polygon size file y / P>

with the spatial information for sample plots Y data.fr Z as the ( with maptools ) and to strengthen ( ggplot2 ) works fine Melt ing X to X_melted works equally well. merge -i Z and X_melted to mapdf also work.

This means that now we have spatial information and long with var1 , var2 , var3 , ... The form has data.frame

Now I want to plot this data frame like this:

  pl1 < - ggplot (mapdf, aes (long, latitude), group = group) pl1 & lt; - Pl1 + geom_polygon (AES (group = group, fill = value), color = "black") pl1 & lt; - pl1 + facet_grid (variable *.) Pl1 & lt; - pl1 + coord_equal (ratio = 1) pl1  

The result is a good conspiracy with one panel for each variable. The panels have the same map, but coloring with the values ​​of variables varies. So far, everything works like a charm ... with a problem:

Variables have different minutes and maximum values ​​for example var1 to < Code> 0 to 5 , var2 to 0 to 400 , Var3 to 5 to 10 , etc. In that example, the legend 0 to 400 for fill color. var2 is well-crafted, but var1 and var3 are basically in the same color.

Is there any way to use a different legend for each panel of the aspect? Or can I create a personal plot for facet_wrap or facet_grid in ggplot

Join them with each variable and viewport, but there are so many variables in it and this will be a lot of work.

Or maybe I can use any other package or method to accomplish what I want to do?

And the help will be greatly appreciated :)

EDIT: ggplot2 - With the help of package descriptions, I have created an example that Describes the problem:

  IDs & lt; - The factor (C ("1.1", "2.1", "1.2", "2.2", "1.3", "2.3")) & lt; - Data.frame (id = id, val1 = cumsum (runif (6, (id = delegate (id, every = 4), x = c (2, 1, 1.1, 2.2), val 2 =, 1, 0, 0.3, 1.1, 2.2, 1.1, 1.2, 2.5, 1.1, 0.3, 0.5, 1.2, 2.5, 1.2, 1.3, 2.7, 1.2, 0.5, 0.6, 1.3), Y = C (-0.5, 0, 1, 0.5, 0, 0.5, 1.5, 1, 0.5, 1, 2.1, 1.7, 1, 1.5, 2.2, 2.1, 1.7, 2.1, 3.2, 2.8, 2.1, 2.2, 3.3, 3.2)) Value & lt; - Melt (values) Datapoly & lt; - merge (by value, position, = c ("id"); p <- ggplot (datapoli, aes (x = x, y = y)) + geom_polygon (AES (fill = value  Var2   

On the right-hand panel, on the var2 map. On the left-hand panel, one of all polygons It's logical, because only one color gradient is used for all the panels. Can I use a different color gradient for each panel?

for everything except X and y).


Comments