stacked bar on single-color printing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

stacked bar on single-color printing

miao
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: stacked bar on single-color printing

Rui Barradas
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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: stacked bar on single-color printing

miao
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 <[hidden email]> 於 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]]
> >
> > ______________________________________________
> > [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: stacked bar on single-color printing

Rui Barradas
Hello,

In base graphics function barplot has arguments angle and density, see
the help page ?barplot. As an example, with the same data (note that the
argument density is recycled, 2 values, one per stacked bar times the
number of unique X vakues):


barplot(Freq ~ Y + X, tbl, density = c(10, 0))


Hope this helps,

Rui Barradas

Às 14:27 de 13/08/20, John escreveu:

> 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 <[hidden email] <mailto:[hidden email]>> 於
> 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]]
>      >
>      > ______________________________________________
>      > [hidden email] <mailto:[hidden email]> 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.
>      >
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: stacked bar on single-color printing

glsnow
In reply to this post by miao
While it is possible to fill bars with patterns, it is not
recommended.  Fill patterns can lead to what is called the Moire
effect and other optical illusions.  Depending on the fill patterns
and how they relate to each other this can cause an illusion of
movement within the plot, straight lines appearing curved, and
distorting of lengths/positions.  Fill patterns (through the
illusions) can subtly move the observer's eye away from the important
parts of a graph and make it hard to focus on the parts of the graph
that are most important.  Google for phrases "Moire effect graphs" and
"optical illusion diagonal lines" for some examples.

Perhaps a dot chart (using symbols instead of colors/greyscale/fill
patterns) would be a better option than a bar chart for your case.

On Thu, Aug 13, 2020 at 7:21 AM John <[hidden email]> wrote:

>
> 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 <[hidden email]> 於 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]]
> > >
> > > ______________________________________________
> > > [hidden email] 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]]
>
> ______________________________________________
> [hidden email] 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.



--
Gregory (Greg) L. Snow Ph.D.
[hidden email]

______________________________________________
[hidden email] 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.