Recreate graph gradient colors in R - r

I'm looking to create very high quality data visualization in R and I'm not sure how to create some of the gradient colors in the in the bar graph below (full link here).
I believe ggplot can do some gradient fills, but in this case, i'd need a stacked color and background color, both of a light grey-to-orange gradient. I can't find a command to do that. The column widths would have to be full and a dark grey border. (i don't need the symbols).
What ggplot (or other) command could replicate this design? Thanks for any direction. Really hoping I can recreate some of my favorite designs in R.

Related

Heat map with opacity gradient

I have two heat maps that I want to overlay to create one combined map. I am looking for a way to make an opacity/alpha gradient instead of a color gradient; that is, transparent->blue instead of white->blue.
I have access to a lot of plotting software (R, mathematica, gnuplot, grace, excel, etc) but I just don't know what program is capable of this kind of gradient.
So far, the best that I can do is make two heat maps in excel, then make one slightly transparent and overlay it on the other. The problem is, this muddles the colors so that the dark shades are no longer dark. This figure can be found here: Excel Heat map overlays
Thank you in advance for any help!
Scott

how to change the gradient of colour in bplot for R

I was wondering if anybody had much experience with the function bplot in R, I am making a 3d plot and the plot works fine. The only thing I want to change is the gradient of colour which you get from drape=TRUE. At the moment it has a single pink colour fading into blue, I really need a third colour in the middle to highlight the central data better as this is the most important for my study, and at the moment in some of the plots I am doing its too difficult to pick out and correlate with the level of y in the colour scale bar.
Does anybody have any idea how to do this?
I need more reputation to post an image of the plot but you can see what I mean in the second image of this thread.
Plot Regression Surface
Many thanks
Aaron
Try adding a colorRampPalette argument to your plot like so:
col.regions = colorRampPalette(colors=c("red","yellow"))(1000)
This will give you a gradient of 1000 shades between red and yellow, You can use any of the R colors in the color ramp, and you can specify more than two e.g.colors=c("red","orange3","palegoldenrod") if you like. You should put this argument at the same place you are putting drape=TRUE

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)

R/quantmod: how to specify the bollinger bands colour?

This could be more generally be How to change the theme colours? Or maybe TA colours are not controlled by theme?
This makes bollinger bands with a nice cloud effect:
chartSeries(bars, theme="white")
addBBands()
(See example of how it looks (near the bottom) )
The cloud effect is dark grey on this next example, so almost invisible.
chartSeries(bars, theme="black")
addBBands()
How do I change it to be, say, a nice bright red, with bright purple for the upper and lower lines? (Yeah, I know, -1 for the colour scheme)
I believe I'll be able to specify an 8-hex-digit colour to specify semi-transparency. But can I do anything more exotic? E.g. it would be rather cool to use a gradient and have it #ff0000 at the centre, fading to #330000 at the upper and lower lines. Is there any gradient support in quantmod charting?
A look at chartTheme seems to indicate that a gradient is not possible, but the up/down colours can be specified, as can the respective border colours. Just define your own theme as per the examples. You can start with the predetermined theme and modify certain individual parameters.
Fleshing out Benjamin's answer and my own learnings, here is an example:
#bars is an XTS object, OHLC data
library(quantmod)
chartSeries(bars)
addBBands(n=20,sd=2)
addBBands(n=50,sd=1)
The above draws two bollinger bands, in default colour scheme. The following will change them to be a semi-transparent red (i.e. the red is stronger where they both exist):
t=chartTheme()
t$BBands$fill="#ff666633" #20% red (i.e. hex 33 is the transparency)
reChart(theme=t)
From my study of the source this should have worked to change the line colours:
t$BBands$col=c('red','blue','green')
But it does not. However you can change the top/bottom colours to the same colour with:
t$BBands$col='blue'
reChart(theme=t)
And here is how to do the same with the newer chart_series() function, and notice you can set the line colours individually (NB. there is no reChart function, as far as I can see):
t=chart_theme()
t$bbands$col$fill="#ff000033"
t$bbands$col$upper='red'
t$bbands$col$lower='green'
t$bbands$col$ma='blue'
chart_Series(bars,theme=t)
add_BBands(n=50,sd=1)
add_BBands(n=20,sd=2)
It is not possible, as far as I know, to use a different colour scheme for each of the two bollinger bands. Even changing the colour scheme like this fails, as after the second command it redraws both with the new colours!
obj=chart_Series(bars)
add_BBands(n=50,sd=1)
obj$Env$theme$bbands$col$fill="#00ff0033"
add_BBands(n=20,sd=2)

R: using hatched fill in plots

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.

Resources