filled.contour in R 3.0.x throws error
This happens if you use a non-standard API. You are allowed to do that, but cannot expect that it is maintained.
Change
.Internal(filledcontour(as.double(x), as.double(y), z, as.double(levels),
col = col))
to
.filled.contour(as.double(x), as.double(y), z, as.double(levels),
col = col)
The change was announced with the release notes:
The C code underlying base graphics has been migrated to the graphics
package (and hence no longer uses .Internal() calls).
Have you ever heard of a "minimal reproducible example" (emphasis on "minimal")?
Placing rows at user-defined distances in filled.contour in R
While I waited for some response here, I kept on trying and actually it was a very silly problem.
You just need to change the default y
argument in filled.contour
Here is the (not significantly) modified function which gives the following image:
filled.contour(z=z1,y=c(0,.33,1),col=col1,cex.lab=2,cex.main=1.1,nlevels=20,main=('Heat map with custom y placement'))
Multiple filled.contour plots in one graph using with par(mfrow=c())
No I do not think this is possible in filled.contour
.
Although extensions have been written for you already. To be found here, here and here and a legend code here.
[If you are using the filled.contour3 function referred to on those sites, and using a more recent version, then you need to use the upgrade fix referred to in this SO post].
Using those codes I produced:
Creating a colour gradient around zero in filled.contour
I have only managed to achieve what you want using ggplot2
.
You can try the following (I submerged the volcano data as an example):
library(ggplot2)
library(reshape2)
## Just an example, I subtract the mean to have positive and negative values for z
dd <- volcano-mean(volcano)
## Creates a data.frame with columns x, y, z
dd <- melt(dd)
names(dd) <- c('x','y','z')
## Does the contour plot
d <- ggplot(dd, aes(x,y,z=z))
d + geom_tile(aes(fill=z)) + scale_fill_gradient2(low="blue", high="red")
I wrote a small function that does what you want to achieve:
myFilled.contour <- function(x = seq(0, 1, length.out = nrow(z)),
y = seq(0, 1, length.out = ncol(z)),
z, nlevels=30, ...) {
ma <- max(abs(z))
lvls <- seq(-ma, ma, length.out = nlevels)
cols <- colorRampPalette(c("blue","white","red")) (nlevels - 1)
filled.contour(x, y, z, plot.axes={axis(1); axis(2)},
col=cols, levels=lvls, ...)
}
Using filled.contour
and again the submerged volcano dd
:
myFilled.contour(z=d)
Using your data:
myFilled.contour(x,y,z)
Caveat: The legend includes levels not used in the contour plot.
Hope it helps,
alex
Error when plotting RasterLayer in R 3.x.x
The problem could be solved by starting a new R-Studio project in a new directory!
First I thought I understand, because it is always possible, that some of my own functions in the environment could have be kind of conflicting, since they were created before 3.x.x.
But then I realized, that I still do not understand , because clearing the environment and history did not help in the first place.
Since I am a curious person, I'm still interested in ideas, which can explain that and I have absolutely no understanding for voting down my question without giving an explanation!
Filled contour plot with R/ggplot/ggmap
It's impossible to test without a more representative dataset (can you provide a link?).
Nevertheless, try:
## not tested..
map = ggmap( baseMap ) +
stat_contour( data = flood, geom="polygon",
aes( x = lon, y = lat, z = rain, fill = ..level.. ) ) +
scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" )
The problem is that geom_contour doesn't respect fill=...
. You need to use stat_contour(...)
with geom="polygon"
(rather than "line").
increasing 'x' and 'y' values expected
As the error message implies, one problem is that in y<-c(10:1)
the y values do not increase...
Besides, z needs to be an x*y matrix.
So try the following:
x<-c(1:10)
y<-c(1:10)
z<-matrix(x,nrow=length(x),ncol=length(y)
persp(x,y,z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
Related Topics
Suppress Automatic Output to Console in R
Preventing Column-Class Inference in Fread()
Gcc: Error: Libgomp.Spec: No Such File or Directory with Amazon Linux 2017.09.1
Difference of Prediction Results in Random Forest Model
R Ggplot2 Boxplots - Ggpubr Stat_Compare_Means Not Working Properly
Match Dataframes Excluding Last Non-Na Value and Disregarding Order
Loading Dplyr After Plyr Is Causing Issues
Problems with Dplyr and Posixlt Data
Arranging Arrows Between Points Nicely in Ggplot2
Compute All Pairwise Differences Within a Vector in R
How to Use a Character Vector of Column Names in the Formula Argument of Dcast (Reshape2)
Installing R on Osx Big Sur (Edit: and Apple M1) for Use with Rcpp and Openmp
Drawing Non-Intersecting Circles