Scatterplot ggplot: too many overlapping point make an area magnified/ increase specific areas
2
0
Entering edit mode
3.0 years ago
camillab. ▴ 160

Hi,

How can I make this scatterplot "wider" around the 0 (or better between -1.5 and +1.5) to see clearly if there is any trend? plot I would like to make a magnification of the area where all the points are overlapping without having to subset/select only those genes and plot it in again? is it possible to do in R (to be honest I am not sure even how to search for it)? here my code:

#scatterplot 
library(ggplot2)
library(ggrepel)
#general graph no labels
ggplot(data = Dpg_TF, aes(x= log2FC, y= -1*log10(p_value)))+ ggtitle("Transcription factors genes Dpg dataset") + 
  geom_point() + 
  geom_point(data= dfdown, aes(x= log2FC, y= -1*log10(p_value)), color = "blue")+
  geom_point(data= dfup, aes(x= log2FC, y= -1*log10(p_value)), color = "red")+
  geom_hline(yintercept = -1*log10(0.05),linetype = "dashed") +
  geom_hline(yintercept = -1*log10(0.01),linetype = "dashed", color = "black")+ 
  geom_text(mapping=aes(x=-140,y=2.0),label=paste("0.01"), color = "black", size = 2.5, vjust=-0.5) +
  geom_hline(yintercept = -1*log10(0.001),linetype = "dashed", color = "black") +
  geom_text(mapping=aes(x=-140,y=3.0),label=paste("0.001"), color = "black", size = 2.5, vjust=-0.5)+
  geom_vline(xintercept = 1.5,linetype = "dashed")+ 
  geom_vline(xintercept = -1.5,linetype = "dashed")

thank you!!

Camilla

overlapping ggplot scatterplot r • 1.6k views
ADD COMMENT
1
Entering edit mode

your code + coord_cartesian(xlim = c(-1.5,1.5)) zooms onto the coordinates.

ADD REPLY
2
Entering edit mode
3.0 years ago

Hi Camilla,

I think that you may try ggforce::facet_zoom(): https://www.data-imaginist.com/2019/the-ggforce-awakens-again/

Kevin

ADD COMMENT
1
Entering edit mode
3.0 years ago
  geom_text(mapping=aes(x=-140,y=2.0),label=paste("0.01"), color = "black", size = 2.5, vjust=-0.5) +
  geom_text(mapping=aes(x=-140,y=3.0),label=paste("0.001"), color = "black", size = 2.5, vjust=-0.5)+

These two lines are likely expanding your scale unnecessarily. Set them to like aes(x=-1.5,y=3.0) and see what it looks like. Set the x-value to something that is at the extreme of your dataset - for example if your furthest point is at +/-2.5 set the x-value to 3.

Even easier is just add this at the end + xlim(-1.5,1.5) it will hide your labels but at least you will be able to see what the resolution looks like with those boundary conditions.

ADD COMMENT

Login before adding your answer.

Traffic: 1604 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6