How to covert Plot_ly codes to ggplot2 codes?
0
0
Entering edit mode
3.0 years ago

Hello, I am using the following codes for producing an overlapping QQ-plot from two GWAS result files.

# first model
a<-read.table("GWAS_result_1.txt" , header=T)
o = -log10(sort(a$P.value, decreasing = FALSE))
e = -log10(ppoints(length(a$P.value)))

# second model
b<-read.table("GWAS_result_2.txt" , header=T)
o2 = -log10(sort(b$P.value, decreasing = FALSE))
e2 = -log10(ppoints(length(b$P.value)))

plotly::plot_ly(x = ~e, y = ~o, name = "p1", 
                type = "scatter", mode = "markers")  %>% 
  add_trace(x = ~e2, y = ~o2, name = "p2") %>% 
  add_trace(x = c(0, max(e,e2)), y = c(0, max(e,e2)), 
            mode="lines", name = "Log normal") %>% 
  layout(xaxis = list(title = 'Expected -log[10](<i>p</i>)'),
         yaxis = list(title = 'Observed -log[10](<i>p</i>)'))

But I am having lots of trouble in saving the image from Plot_ly. I used orca to save the image but it is not working and messing up my R-studio.

Is there any way to use the above plot_ly code in ggplot2 to make life easier while saving a figure?

Thanks

R-studio GWAS visualization ggplot2 • 744 views
ADD COMMENT
0
Entering edit mode

plot_ly syntax directly borrows much from ggplot2. You should be able to refactor the code to use ggplot2 instead pretty easily, and it may even lift over directly if the graph is quite simple.

There is no way to save a plot_ly object 'through' ggplot2 however, you will have to do some code refactoring, or simply save the plots with plot_ly itself.

ADD REPLY
0
Entering edit mode

Ok thank you. I will try that.

ADD REPLY

Login before adding your answer.

Traffic: 2128 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