【问题标题】:Removing points from geom_bar legend ggplot r从 geom_bar 图例 ggplot r 中删除点
【发布时间】:2018-02-13 09:49:17
【问题描述】:

这是我的数据。

Mod <- as.factor(c(rep("GLM",5),rep("MLP",5),rep("RF",5),rep("SVML",5),rep("SVMR",5)))
Manifold <- as.factor(rep(c("LLE","Iso","PCA","MDS","kPCA"),5))
ROC <- runif(25,0,1)
Sens <- runif(25,0,1)
Spec <- runif(25,0,1)
df <- data.frame("Mod"= Mod, "Manifold"= Manifold, "ROC" = ROC, "Sens" = sens, "Spec" = spec)

我正在制作这张图表

resul3 <- ggplot(df, aes(x = Mod, y = ROC, fill= Manifold)) + 
geom_bar(stat = "identity", position = "dodge", color = "black") +
ylab("ROC & Specificity") +
xlab("Classifiers") +
theme_bw() +
ggtitle("Classifiers' ROC per Feature Extraction Plasma") + 
geom_point(aes(y=Spec), color = "black", position=position_dodge(.9)) + 
scale_fill_manual(name = "Feature \nExtraction", values = c("#FFEFCA", 
"#EDA16A" ,"#C83741", "#6C283D", "#62BF94"))

first graph

而我想要的是另一个标题为“特异性”和一个黑点的传奇。我不希望这一点出现在 Manifolds 传说中。

Something like this but without the points inside the manifold squares

【问题讨论】:

  • color 放入geom_pointaes() 以创建第二个图例。
  • 我猜他想彻底摆脱传说中的点点滴滴。
  • 他说他想要another legend with tittle (sic) "Specificity" and a single black point。所以你的答案部分正确,但你需要将第二个图例添加到geom_pointaes

标签: r ggplot2 legend


【解决方案1】:

更改geom_point 行,添加scale_color_manual 并使用@drmariod 的答案中看到的覆盖将导致此图:

ggplot(df, aes(x = Mod, y = ROC, fill= Manifold)) + 
  geom_bar(stat = "identity", position = "dodge", color = "black") +
  ylab("ROC & Specificity") +
  xlab("Classifiers") +
  theme_bw() +
  ggtitle("Classifiers' ROC per Feature Extraction Plasma") + 
  geom_point(aes(y=Spec, color = "Specificity"), position=position_dodge(.9)) + 
  scale_fill_manual(name = "Feature \nExtraction", values = c("#FFEFCA", 
                                                              "#EDA16A" ,"#C83741", "#6C283D", "#62BF94")) + 
  scale_color_manual(name = NULL, values = c("Specificity" = "black")) +
  guides(fill = guide_legend(override.aes = list(shape = NA)))

【讨论】:

    【解决方案2】:

    您可以像这样覆盖形状的美学并将其设置为NA

    ggplot(df, aes(x = Mod, y = ROC, fill= Manifold)) + 
      geom_bar(stat = "identity", position = "dodge", color = "black") +
      ylab("ROC & Specificity") +
      xlab("Classifiers") +
      theme_bw() +
      ggtitle("Classifiers' ROC per Feature Extraction Plasma") + 
      geom_point(aes(y=Spec), color = "black", position=position_dodge(.9)) + 
      scale_fill_manual(name = "Feature \nExtraction", values = c("#FFEFCA", 
      "#EDA16A" ,"#C83741", "#6C283D", "#62BF94")) + 
      guides(fill = guide_legend(override.aes = list(shape = NA)))
    

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      相关资源
      最近更新 更多