问题描述
如何使用具有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
解决方法
热图呢?粗略的例子:
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")
鉴于大量观察结果,考虑将其分解为多个图表。
,很难准确地理解您要做什么。这是您要达到的目标吗?
#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")