是否可以使用ggplot2 2.0
引入的笔画参数来调整条形边框的粗细?如果没有,有没有办法控制沿边界线厚度线的条形边框厚度? 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)
答案 0 :(得分:12)
正如我在OP上建议的那样,我只是将我的评论作为答案重新复制。
您只需在size
表达式中设置geom_bar()
:
geom_bar(stat = "identity", aes(fill = "transparent", size = ifelse(factor2 == "A", 2, 1)), size=2)