使用ggplot2笔画控制栏边框(颜色)厚度 [英] Control bar border (color) thickness with ggplot2 stroke

查看:2305
本文介绍了使用ggplot2笔画控制栏边框(颜色)厚度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用与 ggplot2 2.0 引入的笔画参数来调整条纹周围边框的粗细?如果没有,是否有办法控制沿边界厚度线条的边界厚度?



在评论后编辑
好​​的,多亏了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 =transpa租金,size = ifelse(factor2 ==A,2,1)),size = 2)


Is it possible to use the stroke argument introduced with ggplot2 2.0 to adjust the thickness of borders around bars? If not, is there a way to control bar-border thickness along the lines of point-border thickness? Stroke applies to borders around certain shapes -- see the second answer

A very modest MWE, showing fill only:

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")

EDIT after COMMENT OK, thanks to MLavoie's comment, it was so simple. Here is the code I have ended with, and, no, I am not actually using this plot other than to teach about ggplot and its capabilities.

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)

解决方案

well as I suggested by the OP, I will just recopy my comment as an answer.

you just need to set size in your geom_bar() expression:

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

这篇关于使用ggplot2笔画控制栏边框(颜色)厚度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆