Note that there are some explanatory texts on larger screens.

plurals
  1. POGrid with choropleth maps in ggplot2
    primarykey
    data
    text
    <p>Using Hadley's great ggplot2 and his book (pp. 78-79), I am able to produce single choropleth map plots with ease, using code like this:</p> <pre><code>states.df &lt;- map_data("state") states.df = subset(states.df,group!=8) # get rid of DC states.df$st &lt;- state.abb[match(states.df$region,tolower(state.name))] # attach state abbreviations states.df$value = value[states.df$st] p = qplot(long, lat, data = states.df, group = group, fill = value, geom = "polygon", xlab="", ylab="", main=main) + opts(axis.text.y=theme_blank(), axis.text.x=theme_blank(), axis.ticks = theme_blank()) + scale_fill_continuous (name) p2 = p + geom_path(data=states.df, color = "white", alpha = 0.4, fill = NA) + coord_map(project="polyconic") </code></pre> <p>Where "value" is the vector of state-level data I am plotting. But what if I want to plot multiple maps, grouped by some variable (or two)?</p> <p>Here's an example of a <a href="http://andrewgelman.com/2009/11/senators_and_he/" rel="noreferrer">plot done by Andrew Gelman, later adapted in the New York Times</a>, about health care opinion in the states:</p> <p><img src="https://i.stack.imgur.com/j2xjm.png" alt="enter image description here"></p> <p>I'd love to be able to emulate this example: show choropleth plots gridded according to two variables (or even one). So I pass not a vector of values, but rather a dataframe organized "long", with multiple entries for each state.</p> <p>I know ggplot2 can do this, but I'm not sure how. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload