首页 > 解决方案 > 三个观察的气泡图

问题描述

这是我的数据。我试图在我的气泡图中放置三列。

它们是已更改、未更改和相关的生存 q 值

我的数据框

    dput(df)
    structure(list(Class = c("cell fate commitment", "chromatin remodeling", 
    "chromatin_covalent", "demethylation", "histone methylation", 
    "intracellular receptor signaling pathway", "negative regulation of cell differentiation", 
    "Nuclear Receptor transcription pathway", "PID HDAC CLASSI PATHWAY", 
    "PID SMAD2 3NUCLEAR PATHWAY", "regulation of chromatin organization", 
    "Transcriptional misregulation in cancer"), Altered = c(182, 
    312, 433, 117, 354, 294, 258, 268, 244, 185, 197, 282), Unaltered = c(489, 
    361, 235, 559, 315, 370, 411, 409, 426, 491, 483, 387), `q-Value` = c(0.0009732, 
    1.1e-07, 2.832e-05, 0.137, 0.003188, 0.971, 0.139, 0.0008647, 
    0.002938, 2.843e-06, 3.102e-06, 0.032)), class = c("spec_tbl_df", 
    "tbl_df", "tbl", "data.frame"), row.names = c(NA, -12L), spec = structure(list(
        cols = list(Class = structure(list(), class = c("collector_character", 
        "collector")), Altered = structure(list(), class = c("collector_double", 
        "collector")), Unaltered = structure(list(), class = c("collector_double", 
        "collector")), `q-Value` = structure(list(), class = c("collector_double", 
        "collector"))), default = structure(list(), class = c("collector_guess", 
        "collector")), skip = 1L), class = "col_spec"))
Code for the plot
    xm <- reshape2::melt(df, id.vars = "Class", variable.name = "Samples", value.name = "Size")
    
    # Calculate bubble size
    bubble_size <- function(val){
      ifelse(val > 3, (1/15) * val + (1/3), val)
    }
    
    # Calculate bubble colour
    bubble_colour <- function(val){
      ifelse(val > 3, "A", "B")
    }
    
    # Calculate bubble size and colour
    xm %<>% 
      mutate(bub_size = bubble_size(Size),
             bub_col = bubble_colour(Size))

# Plot data


ggplot(xm, aes(x = Samples, y = fct_rev(Class))) +
  geom_point(aes(size = bub_size, fill = bub_col), shape = 21, colour = "black") +
#  geom_text()
  geom_label_repel(aes(label=Size), size=3)+
  theme(panel.grid.major = element_line(colour = alpha("gray", 0.5), linetype = "dashed"),
        text = element_text(family = "serif"),
        legend.position = "none") + 
  scale_size(range = c(1, 25)) +
  scale_fill_manual(values = c("blue","red")) +
  ylab("Class")

我得到这样的东西

我的身影

如何将两个患者组标记为不同的颜色以及标记数据点,例如两个组的患者编号和图中的 qualue

更新 我可以将标签放入情节中。但无法为患者组更改和未更改组映射两种不同的颜色。

更新无花果

带有标签的更新图

标签: rggplot2

解决方案


推荐阅读