【问题标题】:R ggplot2 scale_shape_manual not working but scale_colour_manual worksR ggplot2 scale_shape_manual 不工作,但 scale_colour_manual 工作
【发布时间】:2020-02-04 16:46:59
【问题描述】:

我想设置我的 2 个指标的颜色和形状,这两个指标被绘制成两层。 scale_color_manual 有效,但是 scale_shape_manual 无效。通过有或没有这条线“scale_shape_manual”;结果是一样的,形状“16”(实心圆)被拾起?

comp_graph_1 <- ggplot() + 
  layer( mapping = aes(x=log(FV), y= msd, colour = "Reference"),   #factor(Dataset) 
  data = ref,
  stat = "identity",
  geom = "point",
  position = "identity")+ 
  layer(mapping = aes(x=log(FV), y= msd,  colour = "Target"),  #  "red" "blue"
        data = target,  #data = target[Is_Phone == 0],  
        stat = "identity",
        geom = "point",
        position = "identity")+ 
  theme(panel.background = element_rect(fill = 'white'), 
        panel.grid = element_line(colour = "grey90") , panel.ontop = FALSE)+ 
  theme(legend.justification = c(0, 0), legend.position = "bottom", 
        legend.background = element_rect(), legend.title = element_blank(), legend.key = element_rect(fill = "white"),
        legend.text = element_text(size = 9,colour = "#7F7F7F"), panel.border = element_blank(), 
        axis.line = element_line(color = "#7F7F7F"))+
  theme(plot.title = element_text(size = 16, colour = "#7F7F7F"), 
        axis.title.x = element_text(size = 11, hjust = 1, face = "bold", colour = "#7F7F7F"), 
        axis.title.y = element_text(size = 11, hjust = 1, face = "bold", colour = "#7F7F7F")) +
  ggtitle(paste0(x, " / ", y, " distribution  ")) + xlab(paste0("log ", x)) + ylab(y) +
  scale_color_manual(values = c("Reference" ="#FFC000","Target"  = "#00AEEF")) +
  scale_shape_manual(values = c("Reference" =17, "Target"  = 4)) 

【问题讨论】:

  • 请提供您输入数据的示例(reftarget)。

标签: r ggplot2


【解决方案1】:

我认为你有 color = "Target" 你也需要一个形状声明 shape = "Target" 和 shape = "Reference" 应该可以工作。

【讨论】:

    猜你喜欢
    • 2021-01-09
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    相关资源
    最近更新 更多