Hi, I would like to create percentage stacked bar with graphics package (e.g., ggplot2) and print it in white/black. The regular option is to use different color on the bar. Is there any way to use different background on a bar so that we can tell on a black/white printing? For example, let my green correspond to ***, while my red correspond to .... Thanks, J [[alternative HTML version deleted]]
Hello, Without sample data and the code you've tried it's difficult to say but are you looking for something like this? set.seed(2020) df1 <- expand.grid(X = factor(1:5), Y = LETTERS[1:2]) df1 <- df1[sample(nrow(df1), 100, TRUE), ] library(ggplot2) tbl <- as.data.frame(table(df1)) ggplot(tbl, aes(X, Freq, color = Y, fill = Y)) + geom_col() + scale_color_manual(values = c("black", "black")) + scale_fill_manual(values = c("white", "gray70")) + theme_bw() Hope this helps, Rui Barradas ?s 10:05 de 13/08/20, John escreveu:> Hi, > > I would like to create percentage stacked bar with graphics package > (e.g., ggplot2) and print it in white/black. The regular option is to use > different color on the bar. Is there any way to use different background on > a bar so that we can tell on a black/white printing? For example, let my > green correspond to ***, while my red correspond to .... > > Thanks, > > J > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Thanks Rui. That's very close to what I am looking for. You use gray scales for different categories. That would be a great idea. Could we use pattern fill? Rui Barradas <ruipbarradas at sapo.pt> ? 2020?8?13? ?? ??6:31???> Hello, > > Without sample data and the code you've tried it's difficult to say but > are you looking for something like this? > > > set.seed(2020) > df1 <- expand.grid(X = factor(1:5), Y = LETTERS[1:2]) > df1 <- df1[sample(nrow(df1), 100, TRUE), ] > > library(ggplot2) > > tbl <- as.data.frame(table(df1)) > > ggplot(tbl, aes(X, Freq, color = Y, fill = Y)) + > geom_col() + > scale_color_manual(values = c("black", "black")) + > scale_fill_manual(values = c("white", "gray70")) + > theme_bw() > > > Hope this helps, > > Rui Barradas > > ?s 10:05 de 13/08/20, John escreveu: > > Hi, > > > > I would like to create percentage stacked bar with graphics package > > (e.g., ggplot2) and print it in white/black. The regular option is to use > > different color on the bar. Is there any way to use different background > on > > a bar so that we can tell on a black/white printing? For example, let my > > green correspond to ***, while my red correspond to .... > > > > Thanks, > > > > J > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > >[[alternative HTML version deleted]]