在ggplot2中,只能在一侧更改条的边界? (颜色,厚度) [英] In ggplot2, can borders of bars be changed on only one side? (color, thickness)

查看:267
本文介绍了在ggplot2中,只能在一侧更改条的边界? (颜色,厚度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,3D Barcharts是一种罪过。但我被要求去做,并且作为一种折衷,我建议只制作比酒吧顶部和右侧酒吧的颜色略深的边框。像那样,酒吧会有某种阴影(urgh),但至少你仍然可以比较它们。

有没有办法做到这一点?

  ggplot(diamonds,aes(clarity))+ geom_bar()


解决方案

另一种可能性是使用两套 geom_bar 。第一套,绿色的,稍高一点,偏右。我借用@Didzis Elferts的数据。

$ g $ p $ ggplot(data = df2)+
geom_bar(aes(x = as.numeric(清晰度)+ 0.1,y = V1 + 100),
width = 0.8,fill =green,stat =identity)+
geom_bar(aes(x = as.numeric (清晰度),y = V1),
width = 0.8,stat =identity)+
scale_x_continuous(name =clarity,
breaks = as.numeric(df2 $ clarity) ,
labels = levels(df2 $ clarity))+
ylab(count)


I know, 3D Barcharts are a sin. But i´m asked to do them and as a trade-off i suggested to only make a border with a slightly darker color than the bar´s on the top and the right side of the bar. Like that, the bars would have some kind of "shadow" (urgh) but at least you still would be able to compare them.

Is there any way to do this?

ggplot(diamonds, aes(clarity)) + geom_bar() 

解决方案

Another possibility, using two sets of geom_bar. The first set, the green ones, are made slightly higher and offset to the right. I borrow the data from @Didzis Elferts.

ggplot(data = df2) + 
  geom_bar(aes(x = as.numeric(clarity) + 0.1, y = V1 + 100),
           width = 0.8, fill = "green", stat = "identity") +
  geom_bar(aes(x = as.numeric(clarity), y = V1),
           width = 0.8, stat = "identity") +
  scale_x_continuous(name = "clarity",
                     breaks = as.numeric(df2$clarity),
                     labels = levels(df2$clarity))+
  ylab("count")

这篇关于在ggplot2中,只能在一侧更改条的边界? (颜色,厚度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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