从 geom_bar 图例 ggplot r 中删除点

标签 r ggplot2 legend

这是我的数据。

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

最佳答案

更改 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)))

enter image description here

关于从 geom_bar 图例 ggplot r 中删除点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763802/

相关文章:

swift - Core Plot 中的可点击图例

r - 一阶差分数据框

r - 使用带有 transition_time 的 geom_map 得到错误 : Error in insert_points(polygon$x, polygon$y, splits, n)

r - ggplot2:如何从 geom_密度图例中删除斜线

r - 如何使用 ggplot2 R 增加整个图的宽度

r - 如何控制哪些几何图形显示在 ggplot2 的哪些图例中?

matlab - Matlab 条形图中的图例

r - 这些 R 变量图标是什么意思?

r - dplyr piping 产生与使用相同代码的基本 R 语法不同的结果

r - 如何使用 data.table 处理空/不完整的子集