R: using hatched fill in plots - r

I was using R to make some plots for a report. I see that the plots don't seem to be so smooth. I am new to R so don't know much. But how do I get smooth plots?
Also by default the plots are filled with solid colors but I want to have hatched fills in my pie charts and bar plots. Is there a way to do that in R, I couldn't find it through a basic google search so I put this question here.

Did you try help(pie)?
density: the density of shading lines, in lines per inch. The default
value of ‘NULL’ means that no shading lines are drawn.
Non-positive values of ‘density’ also inhibit the drawing of
shading lines.
pie(c(1,2,3),density=c(1,2,20))
hist(runif(200),density=c(10,20,30))

Note that cross hatching and filling with lines is a hold over from the days when the only way to get quality graphics was with pen plotters (devices that literally drew the plot using a mechanical arm and a pen). Solid fills did not work well on those devices, often making holes in the paper when trying.
Now with high quality monitors and printers, solid fills are prefered, in fact research has shown that cross hatching can cause optical illusions due to the Moire effect, so are best avoided.
Pie charts are also best avoided, the only thing they do better than bar charts is hide and obscure data. Dotplots are becoming prefered to bar charts and with dotplots you don't need to worry about fills.
I know this does not answer the question you asked, but it does answer the one you should have asked.

The idea that hatching should be consigned to the history books is all well and good, but there are still situations where you have to use hatching rather than solid fills - i.e. when you have to present something in black and white. Many academic journals, for instance, still only have black and white figures so using solid fills isn't an option if you want to do a stack chart with more than a few options.

Related

How to draw pie of pie or bar of bar charts in R (using ggplot2)? [duplicate]

I know it is possible to create such double pie charts in excel like this:
http://chandoo.org/wp/2009/12/02/group-small-slices-in-pie-charts/
but can SPSS or R do this also?
In relation to R:
The answer to the title question is "yes" ... see ?pie
As for the second question, the one in the body - it would be possible but would involve some coding. You'd have to draw two pie charts side by side (which could be managed with two calls to pie) and use segments or arrows (and text if necessary) to do the additional components of the plot.
Here's a rough example:
That required the fig argument of par to get them side-by-side.
(That example required a little fiddling to get right, but it would be possible to write a function to automate the details.)
The main issue I can see would be 'why on earth would you do it?' -- pie charts are a poor way of conveying information of this form. There are alternatives that result in much better ability to distinguish values, and less bias (such as what you get when comparing nearly horizontal vs nearly vertical slices).

Is it possible to create a pie in pie chart in SPSS or R?

I know it is possible to create such double pie charts in excel like this:
http://chandoo.org/wp/2009/12/02/group-small-slices-in-pie-charts/
but can SPSS or R do this also?
In relation to R:
The answer to the title question is "yes" ... see ?pie
As for the second question, the one in the body - it would be possible but would involve some coding. You'd have to draw two pie charts side by side (which could be managed with two calls to pie) and use segments or arrows (and text if necessary) to do the additional components of the plot.
Here's a rough example:
That required the fig argument of par to get them side-by-side.
(That example required a little fiddling to get right, but it would be possible to write a function to automate the details.)
The main issue I can see would be 'why on earth would you do it?' -- pie charts are a poor way of conveying information of this form. There are alternatives that result in much better ability to distinguish values, and less bias (such as what you get when comparing nearly horizontal vs nearly vertical slices).

Replace a plot under the par() function of R

There should be an easy way to deal with this, but I don't know. I'm plotting multiple figures with the par(mfrow=c(5,5)) subplot function of R (i.e. 25 figures). After plotting 10 figures say for example I've done something wrong with the 11th plot, now if I want to plot it again using plot function it takes the space for 12th subplot which means the whole subplot structure changes. I know that par(new=TRUE) would let me re-plotting on the top of the 11th figure, but what if the revised plot is so different that overlapping doesn't work? The idea is to erase the 11th figure and then plot it all over again. How about changing the 1st plot after plotting all 25 figures??
It is possible to use the screen family of functions, though I confess to not being an aficionado of them. As you would hope against, it is only to be used exclusive of par(mfrow=c(5.5)) or even layout(...).
Having said that, it is entirely possible to redraw over a screen. For instances:
split.screen(c(5,5))
for (scr in 1:25) {
screen(scr)
par(mar=rep(0,4)+0.1)
plot(0)
}
screen(7)
par(bg='white') # necessary for some display types
erase.screen()
plot(2)
(This is certainly not a beautiful example, but it is functional.)
Notice the explicit setting of the background color (bg) to white; with some displays where transparency is assumed, not doing this will appear to have no affect (that is, erase.screen() will do nothing).
Having said that, there are many modern and near-modern graphing functions/libraries/packages that do things that this package does not support. I have not tested this with image-capturing mechanisms (such as sandwiching things in png(file="...") and dev.off()). Caveat emptor!

ggplot: Pallete Greyscale On Print, Colourful on Screen [duplicate]

I've started to produce the charts for a paper. For some of them which are bar charts I've used the "Pastel1" palette (as recommended in the book on ggplot2, pastel colours are better than saturated ones for fill areas, such as bars).
The problem with Pastel1 at least is that when printed on a B&W laser printer, the colours are indistinguishable. I don't know if the readers will view the paper on screen or will print it on B&W, so I'm looking for either of the following:
how to add hash lines to a palette such as Pastel1 (hopefully the hash lines are also subtle)
a colour palette easy on the eyes that also produces distinct grey areas for B&W for, say, up to 3-4 different colours.
Granted, I could find the latter by experimenting and using toner, but perhaps this has already been solved, I suppose it's a common problem. And yes, I did google for this, but didn't find anything pertinent.
Thank you.
Use http://colorbrewer2.org/ and only show colour schemes that are printer friendly.
Also see scale_fill_grey.
Currently it's not possible to used hash lines due to a limitation in the underlying grid drawing package.
There is the col2grey function in the TeachingDemos package that will convert a set of colors to an approximation of the grey color that will result from printing. You can use this to try different pallettes without wasting toner/paper.
Use this to select another color combination (gray scale option included)

ggplot: recommended colour palettes also distinguishable for B&W printing?

I've started to produce the charts for a paper. For some of them which are bar charts I've used the "Pastel1" palette (as recommended in the book on ggplot2, pastel colours are better than saturated ones for fill areas, such as bars).
The problem with Pastel1 at least is that when printed on a B&W laser printer, the colours are indistinguishable. I don't know if the readers will view the paper on screen or will print it on B&W, so I'm looking for either of the following:
how to add hash lines to a palette such as Pastel1 (hopefully the hash lines are also subtle)
a colour palette easy on the eyes that also produces distinct grey areas for B&W for, say, up to 3-4 different colours.
Granted, I could find the latter by experimenting and using toner, but perhaps this has already been solved, I suppose it's a common problem. And yes, I did google for this, but didn't find anything pertinent.
Thank you.
Use http://colorbrewer2.org/ and only show colour schemes that are printer friendly.
Also see scale_fill_grey.
Currently it's not possible to used hash lines due to a limitation in the underlying grid drawing package.
There is the col2grey function in the TeachingDemos package that will convert a set of colors to an approximation of the grey color that will result from printing. You can use this to try different pallettes without wasting toner/paper.
Use this to select another color combination (gray scale option included)

Resources