Entering edit mode
4 months 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)]