如何使用具有83列的excel存档的barplot()或ggplopt()制作图形栏?我需要在ich raw上绘制值>0的每一列。(ich列代表一个基因功能,我需要知道在ich集群上有多少个功能)。
我试过了,但没起作用:
ggplot(x, aes(x=Cluster, y=value, fill=variable)) +
geom_bar(stat="bin", position="dodge") +
theme_bw() +
ylab("Funções no cluster") +
xlab("Cluster") +
scale_fill_brewer(palette="Blues")指向excel的链接:https://github.com/annabmarques/GenesCorazon/blob/master/AllclusPathwayEDIT.xlsx
发布于 2020-09-25 09:31:51
热图怎么样?一个粗略的例子:
library(dplyr)
library(tidyr)
library(ggplot2)
library(openxlsx)
data <- read.xlsx("AllclusPathwayEDIT.xlsx")
data <- data %>%
mutate(cluster_nr = row_number()) %>%
pivot_longer(cols = -c(Cluster, cluster_nr),
names_to = "observations",
values_to = "value") %>%
mutate(value = as.factor(value))
ggplot(data, aes(x = cluster_nr, y = observations, fill = value)) +
geom_tile() +
scale_fill_brewer(palette = "Blues")考虑到大量的观察结果,可以考虑将其分解为多个图表。

发布于 2020-09-25 10:20:00
很难确切地理解你想要做什么。这就是你想要实现的吗?
#install.packages("readxl")
library(tidyverse)
library(readxl)
read_excel("AllclusPathwayEDIT.xlsx") %>%
pivot_longer(!Cluster, names_to = "gene_counts", values_to = "count") %>%
mutate(Cluster = as.factor(Cluster)) %>%
ggplot(aes(x = Cluster, y = count, fill = gene_counts)) +
geom_bar(position="stack", stat = "identity") +
theme(legend.position = "right",
legend.key.size = unit(0.4,"line"),
legend.text = element_text(size = 7),
legend.title = element_blank()) +
guides(fill = guide_legend(ncol = 1))
ggsave(filename = "example.pdf", height = 20, width = 35, units = "cm")

https://stackoverflow.com/questions/64056110
复制相似问题