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.