ENV
R 3.3.1
mini data
rdn<-c(0.8,1.8,2.8)
tdn<-c(1,2,3,4,5,6,7,8,9)
idn<-matrix(c(0.3, 0.3, 0.3, 0.2, 0.2, 0.4, 0.1, 0.1, 0.5, 0, 0.2, 0.5, 0, 0.3, 0.6, 0, 0.4, 0.6, 0, 0.4, 0.6, 0, 0.5, 0.7, 0, 0.5, 0.7), nrow=9, ncol=3, byrow=T)
What I have now:
code
filled.contour(tdn, rdn, idn,
color.palette=colorRampPalette(c("blue","yellow","red")),
plot.title=title(main="Detail", sub="detail",
xlab="t", ylab="lambda"),
plot.axes = { axis(side = 1, at = tdn, labels = tdn)
axis(side = 2, at = rdn, labels = rdn) },
key.title=title(main="ratio"),
key.axes = axis(4, seq(0, 1, by = 0.1)))
Current Result
Problem
The color range is not what I want. There are borders among colors so colors do not change smoothly from deep blue to deep red.
Expected
Question
how to make colors change smoothly like my Expeced figure when plotting in R? How do I remove problems above? And rainbow
not works for me either. Thanks.
EDIT
Follow Haboryme's solution
The foreground not disappear.
Unfortunately,
filled.contour
...fixes the number of levels/colours between the plot and key, so experimenting with the
nlevels
argument (andcol
insteadcolor.palette
) results in a weird output (smoother image, but unreadable key).In addition, the contour lines cannot be modified. Thus, an increase to 200 levels (from initially 14 in your example) is still 'readable', but higher values generate unwanted side-effects.
Example:
Output:
Maybe experimenting with
lattice::levelplot
solves the problem. At least for the legend color key, a higher number of levels does not disturb. But the image is not 'smoothed'.Example:
Output:
Close to @setempler answer but you might find it a bit closer to your expected output: