0

I'd like to overlay two density plot from two one-dimensional array. I need them both in log-log scale. The files contain just the list of numbers (1.000.000) both generated from very similar specific distributions with a small peak around 4000, thus the log scale on one or both axes.

> prova
   [1]    1.106172    2.617064    1.778360    1.372890    5.334664    2.019493
   [7]    1.174879    1.371897    4.018011    1.220845    3.631309    1.437586 ...

One of the two files, they are both quite similar

https://drive.google.com/file/d/1HEHWZR0Gl6YB1tLFF4WjXFp5ZoB-DrlW/view?usp=drivesdk

This is what I use for just one array:

#Packages
library(tidyverse)
library(plotly)
library(ggplot2)
library(scales)
library(ggforce)

prova <-readRDS("probcond1.rds")
prova1 <-readRDS("probpoly.rds")
dfGamma <-data.frame(prova)

g <- ggplot(dfGamma, aes(x=prova)) +
  stat_density(aes(y=..count..), color="black", fill="blue", alpha=0.3) + scale_x_continuous(breaks=c(0,1,2,3,4,5,10,30,100,300,1000,2000,3000,4000,5000), trans="log1p", expand=c(0,0)) + scale_y_continuous(expand=c(0,0), trans="log1p") + theme_bw()

I tried to copy a solution seen in another answer but in this case weirdly the graph is not in log-log scale.

x <- data.frame(v1=prova,v2=prova1)
data<- melt(x)
ggplot(data,aes(x=value, fill=variable)) + stat_density(alpha=0.3) +
scale_x_continuous(breaks=c(0,1,2,3,4,5,10,30,100,300,1000,2000,3000,4000,5000), trans="log1p", expand=c(0,0)) +
  scale_y_continuous(expand=c(0,0), trans="log1p") +
  theme_bw()

I'm very new to R and I'm not sure how can I build a data.frame from my two lists and how can I manipulate it. Thank you fro your patience.

davideor
  • 21
  • 4
  • Please provide a [reproducible minimal example](https://stackoverflow.com/q/5963269/8107362) – mnist Nov 01 '19 at 22:38
  • There is no much else. I edited anyway, I'd like to upload the two files with the numbers but it's not possible for what I see. They are composed anyway just by 1.000.000 numbers from a specific distribution where a log-log scale makes sense. – davideor Nov 02 '19 at 08:52
  • Could you provide, at least, few records of data with the actual structure and your output error, please? – powerPixie Nov 02 '19 at 09:46
  • There is no error, the problem is that I don't really know how to achive what i want. The distribution in question is a polynomial with a peculiar peak around 4000, thus the log scale on one or both axes. – davideor Nov 02 '19 at 10:19
  • Once again, if you dont provide any sample data its cumbersome for the community to find a solution. Most users wont bother themselves to simulate some data. It's the person who asks for help that is in charge for that. – mnist Nov 03 '19 at 07:51
  • I already did it but the answer under which there was the link in a comment has been removed. It’s now on the question itself. – davideor Nov 03 '19 at 07:58

0 Answers0