Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a facet_wrap plot with ggplot2 with different annotations in each plot
    primarykey
    data
    text
    <p>I am using ggplot2 to explore the result of some testing on an agent-based model. The model can end in one of three rounds per realization, and as such I am interested in how player utilities differ in terms of what round the game ends and their relative position in 2D space.</p> <p>All this is to say that I have generated a facet_wrap plot to show this for each round, but I would also like to annotate each plot with the cor(x,y) for the subset of data represented in each facet. Is there a way to tell ggplot2 that I would like the annotation to use the subset of data generated by facet_wrap? Here is the code I have so far, and what it is producing</p> <pre><code>library(ggplot2) # Load data abm.data&lt;-read.csv("ABM_results.csv") # Create new colun for area of Pareto set attach(abm.data) area&lt;-abs(((x3*(y2-y1))+(x2*(y1-y3))+(x1*(y3-y2)))/2) abm.data&lt;-transform(abm.data,area=area) detach(abm.data) # Compare area of Pareto set with player utility png("area_p1.png",res=100,pointsize=20,height=500,width=1600) area.p1&lt;-ggplot(abm.data,aes(x=area))+geom_point(aes(y=U1_2,colour="Player 1",alpha=0.4))+facet_wrap(~round,ncol=3)+ annotate("text",0.375,-1.25,label=paste("rho=",round(cor(abm.data$area,abm.data$U1_2),2)), parse=TRUE)+ scale_colour_manual(values=c("Player 1"="red")) area.p1+xlab("Area of Pareto Set")+ylab("Player Utility at Game End")+ opts(title="Final Player 1 Utility by Pareto Set Size and Round Game Ends",legend.position="none") dev.off() </code></pre> <p><a href="http://www.drewconway.com/zia/wp-content/uploads/2010/01/area_p1.png">area_p1 http://www.drewconway.com/zia/wp-content/uploads/2010/01/area_p1.png</a></p> <p>As you can see, there are two problems:</p> <ol> <li>The \rho value is of the full dataset, rather than the subsets by 'round'. Is there a way to get the cor(x,y) to print based on only the data shown in each plot?</li> <li>The annotation should read "\rho=some_value" but instead I get "=(\rho,value);" is there a way to fix this? </li> </ol>
    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