简体   繁体   中英

Dividing lines between sections of bar plot with ggplot2 in r

I am using qplot to create a stacked bar plot and would like to place a white line between the sections of each bar as the blues seem to almost blend together. I do not want to change my existing colour scheme to resolve the problem. Any ideas?

library(ggplot2)
qplot(carat, data = diamonds, geom = "histogram", fill = color)

在此输入图像描述

Add the argument colour="white" to create a white outline:

ggplot(mtcars, aes(factor(cyl), fill=am, group=am)) + geom_bar(colour="white")

在此输入图像描述


Here is a workaround to remove the diagonal line from the legend (inspired by a posting on ggplot mailing list ). The idea is to plot the geom_bar twice, once suppressing the colours:

ggplot(mtcars, aes(factor(cyl), fill=am, group=am)) + 
  geom_bar() +
  geom_bar(colour="white", show_guide=FALSE)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM