Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting ggplot plot map into 3 frames

Tags:

split

r

ggplot2

Is it possible to extract specific sections of a ggplot figure/map and place them side by side in a secondary figure but still add points to the three frames as if they were still one plot i.e. for the following map

enter image description here

create a map split into 3 sections which can then be manipulated as one graph (i.e. adding points to all three sections of the graph simultaneously?

enter image description here

UPDATE: Reproducible example

set.seed(1)
dfx<-c(sample(1:1000,100),sample(2000:3000,100),sample(4000:3000,100))
dfy<-c(sample(1:1000,100),sample(2000:3000,100),sample(4000:3000,100))

p<-ggplot()+
coord_fixed()+
geom_point(aes(x=dfx,y=dfy))
p

enter image description here

like image 517
Elizabeth Avatar asked Mar 08 '26 11:03

Elizabeth


1 Answers

I can get partway there but can't retain the effects of coord_equal or coord_fixed while allowing free scales ... hopefully someone else can step in and get the rest of the way. (This has come up before -- scatterplot with equal axes -- but I haven't seen a solution.)

dd <- data.frame(dfx,dfy)
dd2 <- transform(dd,panel=cut(dfx,seq(0,4000,by=1000),labels=1:4))
p <- ggplot(dd2)+geom_point(aes(dfx,dfy)) + coord_equal()
p + facet_wrap(~panel,nrow=1,scale="free")
like image 97
Ben Bolker Avatar answered Mar 10 '26 00:03

Ben Bolker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!