我的数据来自rna_seq分析.我试图描绘CPM和频率,只是将一些上下文放在不同基因的零频率(CPM)上
我提供了一些名为DAT的小数据集.从这个数据集中,我想跟着做一些类似的事情.
# Create an empty list to store ggplot objects
histogram_plots <- list()
# Iterate through the elements
for (element in goi) {
# Filter data for the specific element
element_data <- dat[dat$Gene == element, ]
# Create a ggplot histogram for the element
plot <- ggplot(element_data, aes(x = CPM, y = after_stat(Frequency / sum(Frequency)))) +
geom_histogram(fill = "cornflowerblue", color = "white", binwidth = 5) +
labs(title = paste("Frequency Distribution of", element),
y = "Percent",
x = "CPM") +
scale_y_continuous(labels = scales::percent_format()) +
theme_minimal()
# Add the ggplot object to the list
histogram_plots[[element]] <- plot
# Save the ggplot object as an image file (adjust the filename and format accordingly)
ggsave(paste0("histogram_", gsub("-", "_", element), ".png"), plot, width = 8, height = 6)
}
geom_histogram()
中的错误:
好了!将统计数据映射到美学时出现问题.
第1层出现ℹ错误.
由错误引起的:
好了!Objeto‘频率’没有禁忌
运行rlang::last_trace()
查看错误发生的位置.
抛出找不到频率,但显然存在的错误.我不确定这是否与NSE和这些工作人员有关
《DF》
dat <- structure(list(Gene = c("hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p",
"hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p",
"hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p",
"hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p",
"hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p", "hsa-miR-139-5p",
"hsa-miR-139-5p", "hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p",
"hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p",
"hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p",
"hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p",
"hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p", "hsa-miR-144-3p",
"hsa-miR-144-3p", "hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p",
"hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p",
"hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p",
"hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p",
"hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p", "hsa-miR-15a-5p",
"hsa-miR-15a-5p", "hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p",
"hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p",
"hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p",
"hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p",
"hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p", "hsa-miR-28-3p",
"hsa-miR-28-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p",
"hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p",
"hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p",
"hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p",
"hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p", "hsa-miR-92a-3p",
"hsa-miR-92a-3p"), CPM = c(140, 840, 820, 1740, 100, 460, 40,
940, 760, 340, 620, 680, 380, 1360, 660, 1440, 180, 360, 720,
1100, 2000, 0, 4300, 8600, 1200, 9100, 3100, 7300, 5100, 4100,
3200, 9400, 6600, 2600, 2200, 7800, 2400, 10100, 6900, 8500,
2600, 450, 2800, 2750, 0, 1400, 1550, 650, 1800, 1300, 3200,
1750, 2300, 2500, 300, 8050, 600, 1950, 3150, 750, 140, 580,
380, 500, 570, 740, 30, 490, 410, 250, 340, 540, 550, 260, 350,
470, 680, 100, 180, 530, 3700, 100, 2900, 2100, 2800, 1700, 6900,
2200, 2600, 2150, 1300, 300, 350, 3200, 1500, 1650, 2700, 2550,
1850, 3600), Frequency = c(7, 2, 3, 2, 2, 4, 1, 2, 2, 7, 2, 1,
5, 1, 3, 1, 5, 1, 3, 2, 3, 21, 8, 1, 5, 1, 4, 2, 4, 3, 2, 1,
1, 2, 4, 2, 7, 1, 2, 2, 2, 3, 2, 1, 30, 7, 2, 6, 5, 6, 1, 4,
3, 2, 3, 1, 4, 8, 1, 5, 1, 2, 5, 1, 1, 1, 1, 1, 2, 3, 1, 4, 2,
1, 4, 1, 1, 4, 3, 2, 1, 3, 1, 3, 1, 4, 1, 2, 1, 1, 3, 3, 9, 1,
5, 6, 1, 1, 4, 1)), row.names = c(NA, -100L), class = "data.frame")