ggplot2 geom_density() density value estimates can be greater than 1?
0
0
Entering edit mode
8 days ago
Prawesh • 0

I was trying to get the TPM density plot of RNA-seq samples (Around 500+).

I used the geom_density and density() function. I found that density() and geom_density() is a kernel density estimation. I assume that in density curve area under the curve is 1 so all the values should be below one. But I am getting max density value for a specific sample as 851 which is way more than expected. Can the density estimation value be more than 1?

I used this code.

tpm <- ggplot(filtered_tpm, aes(x=TPM, by=sample_name)) +  
    geom_density(alpha=0.5,color="black",adjust = 0.5) +   
    scale_x_continuous(breaks = c(-1, 5, 10, 15, 20), limits = c(0.3, 20)) +   
    labs(title="TPM Distribution") +   
    theme(
    title = element_text(),
    axis.text = element_text(),
    axis.title = element_text(),
    axis.title.x = element_text(),
    axis.title.y = element_text(),
     panel.background = element_blank(),
     legend.position = "right"   ) 

get_max_density_tpm <- function(each_sample_data){  
each_sample_density <- density(each_sample_data$TPM)   
max_density <- max(each_sample_density$y)   
return (list(max_density=max_density)) }

tpm_density_df <- filtered_tpm[,get_max_density_tpm(.SD),keyby = .(sample_name)][order(max_density,decreasing = T)]
R tpm density ggplot • 125 views
ADD COMMENT

Login before adding your answer.

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