Reputation: 141
This question is part of a project to plot genetic maps in R. The common representation is a "scale" of horizontal trait bordered by two half circle. genetic map example genetic maps are roughly a sequence of position.
I'm trying to make a half circle matching the "ladders of the scale" and with adjustable high so that it always look like a circle and not like some sort of oval shape.
library(ggforce)
df <- data.frame(position=rnorm(n=15)*10)
ggplot(aes(xmin=-2.5,ymin=position-0.1,xmax=2.5,ymax=position+0.1),data=df)+
geom_rect() +
geom_arc_bar(aes(x0 = 0, y0 = max(position), r0 = 0, r = 2.5, start =-pi/2,end = pi/2), color = "grey20")+
geom_arc_bar(aes(x0 = 0, y0 = min(position), r0 = 0, r = 2.5, start = pi/2,end = 3*pi/2), color = "grey20")
So my question is: How to make a reactive shape scaling with the size of Rplot viewing window so that the shape always look like a circle and stay link to my upper "ladder"?
I can adjust manually the size of the plot so that x.axis and y.axis have the same scale before exporting the graph but this is not quite efficient and will become really difficult if I have multiple chromosome on the same plot.
I would be glad to answer comments if needed and hope my question is clear enough!
Upvotes: 2
Views: 169
Reputation: 35377
coord_fixed
will make sure that the x
and y
are always scaled 1:1, even when rescaling the plot.
ggplot(aes(xmin=-2.5,ymin=position-0.1,xmax=2.5,ymax=position+0.1),data=df)+
geom_rect() +
geom_arc_bar(aes(x0 = 0, y0 = max(position), r0 = 0, r = 2.5, start =-pi/2,end = pi/2), color = "grey20")+
geom_arc_bar(aes(x0 = 0, y0 = min(position), r0 = 0, r = 2.5, start = pi/2,end = 3*pi/2), color = "grey20") +
coord_fixed()
Upvotes: 2