Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1898454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:46:01+00:00 2026-05-17T06:46:01+00:00

Sorry for not included any example data for my problem. I couldn’t find a

  • 0

Sorry for not included any example data for my problem. I couldn’t find a way to easily produce an example shape file. Hopefully, experienced users of ggplot can see what I’d like to do from the description below.

I’ve got:

  • A data.frame X with information about sample plots (plotid, var1, var2, var3, var4, …)

  • A polygon shapefile Y with spatial information for the sample plots

Importation of the shapefile Y (with maptools) and fortifying as data.frame Z (ggplot2) works fine. melting X to X_melted works equally fine. merge-ing Z and X_melted to mapdf works as well.

That means that now we have a data.frame in long form with spatial information and var1, var2, var3, …

Now I want to plot this data frame like this:

pl1 <- ggplot(mapdf,aes(long,lat),group=group)
pl1 <- pl1 + geom_polygon(aes(group=group,fill=value),colour="black")
pl1 <- pl1 + facet_grid(variable ~ .)
pl1 <- pl1 + coord_equal(ratio = 1)
pl1

The result is a nice plot with one panel for each variable. The maps of the panels are identical, but fill colour varies with the values of the variables. Up to now, everything works like a charm… with one problem:

The variables have different min and max values. For example var1 goes from 0 to 5, var2 from 0 to 400, var3 from 5 to 10, etc. In that example, the legend for the fill colour goes from 0 to 400. var2 is nicely drawn, but var1 and var3 are basically in the same colour.

Is there a way I could use a different legend for each panel of the facet? Or is this simply not (yet) possible with facet_wrap or facet_grid in ggplot?

I could make individual plots for each variable and join them with viewports, but there a plenty of variables and this would be a lot of work.

Or is there maybe another package or method I could use to accomplish what I’d like to do?

And help would be very much appreciated. 🙂

Edit:
With the help of the ggplot2-package description, I constructed an example that illustrates my problem:

ids <- factor(c("1.1", "2.1", "1.2", "2.2", "1.3", "2.3"))
values <- data.frame(
id = ids,
val1 = cumsum(runif(6, max = 0.5)),
val2 = cumsum(runif(6, max = 50))
)
positions <- data.frame(
id = rep(ids, each = 4),
x = c(2, 1, 1.1, 2.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)
)

values <- melt(values)
datapoly <- merge(values, positions, by=c("id"))

p <- ggplot(datapoly, aes(x=x, y=y)) + geom_polygon(aes(fill=value, group=id),colour="black")
p <- p + facet_wrap(~ variable)
p

The panel on the right illustrates different values for var2 on the map. On the panel on the left however, all polygons have the same colour. This is logical, because only one colour gradient is used for all panels. Could I use a different colour gradient for each panel?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:46:02+00:00Added an answer on May 17, 2026 at 6:46 am

    Currently there can be only one scale per plot (for everything except x and y).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry, for the cryptic title i didn't find any better summary for my problem.
Sorry for the verbose question, but I can't see any other way to make
Sorry for any incorrect terms as I am not proficient in SQL... I have
Random question, sorry if not appropriate for stackoverflow, but I didn't think it would
Sorry for the not so great title, but I'm curious how people build a
Sorry this is not a very well defined question, I am thinking about an
(Sorry I'm not good at English) I haved created a custom BaseAdapter to show
Sorry I am not familar with Python... It gives me the following error message
I could be not more sorry guys - the question was a very wrong
I recently saw some Clojure or Scala (sorry I'm not familiar with them) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.