是否可以使用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所建议的那样,我将重新复制我的评论作为答案。
您只需要在size
表达式中设置geom_bar()
:
geom_bar(stat = "identity", aes(fill = "transparent", size = ifelse(factor2 == "A", 2, 1)), size=2)
关于r - ggplot2笔划的控制栏边框(颜色)厚度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34878848/