我创建了一个闪亮的应用程序,用户可以选择基因并查看与之关联的表格和图表。
目前我正在尝试添加一项功能, 用户选择一个模块,然后用户将看到我附加的数据表,
我的问题是关于我在尝试时,在热图中绘制此用户选择的数据,但是当我在下面的代码的帮助下绘制它时,它不知道选择哪个位置
我可以使用max& abs函数选择具有最高值的loacation。
示例:gene_name ABC有3个位置然后它应该比较这三个位置并显示具有最大值的位置
指向表格的链接 - > https://i.stack.imgur.com/yAwMk.png
#server.r code
buildPlot969 <- reactive({
abcd=data_user()# here this function have the user selected module data
# plot code chunk
h2=Heatmap(reshape2::dcast(abcd,Gene_name~sample_Id,value.var="values")
%>% data.frame(.,row.names = "Gene_name")
%>% apply(.,1function(x)(x-mean(x))/sd(x)),
fun.aggregate=function(x){x[which.max(abs(x))]})
})
output$heat_cell1 <- renderPlot(
{
buildPlot969()
},
height = 700
)
答案 0 :(得分:0)
abcd=data_user()
abcd_1<-as.data.frame(unite(abcd,GENE_NAME_ID,Gene_name,sample_id,remove = FALSE)) # first unite two columns of that data frame to get that value
test<-as.character(unique(abcd_1$GENE_NAME_ID)) # get the unique gene name id
# using sapply function inside that colMaxs from fBasics package which can look
into all columns and get the maximum value
Masx_gene_value<-sapply(test,function(x) colMaxs(abcd_1$atac_log_fc[grep(x, test)]))
# got the max values saved it in "Masx_gene_value"
# converted it into data frame
Masx_gene_value<-as.data.frame(Masx_gene_value)
Masx_gene_value$GENE_ID<-rownames(Masx_gene_value)
rownames(Masx_gene_value)<-NULL
Masx_gene_value$GENE_ID<-sub("_","@",Masx_gene_value$GENE_ID)
abcd_2<-as.data.frame(Masx_gene_value %>% separate(GENE_ID,c("Gene_name","ID"),sep = "@"))
#removed some unwanted data from top and used it in map
h1=Heatmap(reshape2::dcast(abcd_2,Gene_name~ID,value.var="Masx_gene_value") %>% data.frame(.,row.names = "Gene_name") %>% apply(.,1,function(x) (x-mean(x))/sd(x)) %>% t())
draw(h1)