用ggplot2描边控制条边框(颜色)粗细

Control bar border (color) thickness with ggplot2 stroke

是否可以使用 ggplot2 2.0 中引入的 stroke 参数来调整条形边框的粗细?如果没有,有没有办法沿着点边界厚度线控制条边界厚度? Stroke applies to borders around certain shapes -- see the second answer

非常普通的 MWE,仅显示填充:

factor <- c("One", "Two", "Three", "Four")
value <- c(1, 2, 3, 4)
factor2 <- c("A", "B", "A", "B")

df <- data.frame(factor = factor(factor, levels = factor),
                 value = value, factor2 = factor2) 

ggplot(df, aes(x = factor, y = value, color = factor2)) +
  geom_bar(stat = "identity")

评论后编辑 好的,感谢 MLavoie 的评论,它是如此简单。这是我结束的代码,不,除了教授 ggplot 及其功能之外,我实际上并没有使用这个图。

ggplot(df, aes(x = factor, y = value, color = factor2)) +
  scale_color_manual(values = c("darkgreen", "slateblue4")) +
  geom_bar(stat = "identity", aes(fill = "transparent", size = ifelse(factor2 == "A", 2, 1))) +
  guides(fill = FALSE) +
  guides(size = FALSE) +
  guides(color = FALSE)

正如 OP 所建议的那样,我将复制我的评论作为答案。

您只需要在 geom_bar() 表达式中设置 size

geom_bar(stat = "identity", aes(fill = "transparent", size = ifelse(factor2 == "A", 2, 1)), size=2)