您好,我有一个简单的闪亮应用程序,可以创建一个热图 . 问题是,在我将初始数据集融入"gen3"之后,我得到了像 gen3[,1]: DADA
这样的标签名称,但我想采用 gene_symbol: DATA
(我希望与其他标签一样) . 这可能与ggplot2有关吗?我假设我应该以某种方式使用 paste()
或手动更改标签 .
#data
gene_symbol<-c("DADA","SDAASD","SADDSD","SDADD")
ASDDA<-c("normal","over","low","over")
ASDDb<-c("normal","over","low","over")
ASDDAf<-c("normal","over","low","over")
Gene_states2<-data.frame(gene_symbol,ASDDA,ASDDb,ASDDAf)
#ui.r
library(shiny)
library(ggplot2)
library(plotly)
library(extrafont)
library(dplyr)
fluidPage(
# App title ----
titlePanel(div("GENES HEATMAP",style = "color:blue")),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(width = 3
),
# Main panel for displaying outputs ----
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Heatmap",
fluidRow(
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
plotlyOutput("sc")
)
))
)))
#server.r
function(input, output,session) {
rt <-reactive({req(input $ file1)
csvdata <- read.csv(input$file1$datapath,
header = input$header
)
if(input$disp == "head"){
head(csvdata)
} else{
csvdata
}
row.has.na <- apply(csvdata, 1, function(x){any(is.na(x))})
csvdata2 <- csvdata[!row.has.na,]
csvdata2
})
output$sc<-renderPlotly({
library(ggplot2); library(reshape2)
gen3 <- melt(rt(), id.var = colnames(rt())[1])
p1<-ggplot(gen3, aes(gen3[,1],gen3[,2])) + geom_tile(aes(fill = gen3[,3]),
colour = "white") + scale_fill_manual(values=c("yellow", "red", "blue"))+
labs(x = "gene_symbol",y="sample",fill="value")+
theme(title = element_text(family = "Calibri",
size = 10,
face = "bold"),
axis.title = element_text(family = "Calibri Light",
size = 16,
face = "bold",
color = "black"),
axis.text = element_text(family = "Calibri",
size = 11),
axis.title.y = element_text(margin = margin(t = 0, r = 25, b = 0, l = 25)),
panel.background = element_rect(fill = NA),
panel.grid.major = element_line(colour = "grey50"))
ggplotly(p1)%>%
layout( autosize = F, width = 1450, height = 600,hoverlabel = list(bgcolor = "white",
font = list(family = "Calibri",
size = 9,
color = "black")))
})
}
1 回答
在ggplot中,在您已经告诉它使用哪个data.frame之后,不需要在美学(aes)中指定data.frame名称 .
只需这样做:
ggplot(gen3, aes(gene_symbol, variable)) + geom_tile(aes(fill= value)
...等等 .如果您不希望
variable
和value
显示在您的hoverlabel中,只需在将其融合到您想要显示的内容后更改gen3的colnames .