ENV
R 3.3.2
I am plotting raster contour plot using ggplot follow sample code:
library(ggplot2)
v <- ggplot(faithfuld, aes(waiting, eruptions, z = density))
v + geom_raster(aes(fill = density)) +
geom_contour(colour = "white")
My code and mini data is:
pdf(file="graster.pdf")
par(mfrow=c(2,2))
library(ggplot2)
v <- ggplot(faithfuld, aes(waiting, eruptions, z = density))
v + geom_raster(aes(fill = density)) +
geom_contour(colour = "white")
#print(faithfuld)
##### below: my code ########
b<-c(0.8,1.8,2.8)
p<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)
nvalue<-c(
0.3, 0.2, 0.1, 0, 0, 0, 0, 0, 0,
0.3, 0.2, 0.1, 0.2, 0.3, 0.4, 0.4, 0.5, 0.5,
0.3, 0.4, 0.5, 0.5, 0.6, 0.6, 0.6, 0.7, 0.7
)
myarray<-array(nvalue, c(length(p), length(b)), dimnames=list(p,b))
odftarget<-as.data.frame.table(myarray) # change to data.frame
names(odftarget) <- c('p', 'b', 'v')
dftarget <- data.frame( # restore to new data.frame without factor
p=as.numeric(as.character(odftarget$p)),
b=as.numeric(as.character(odftarget$b)),
v=odftarget$v
)
head(dftarget)
library(tibble)
tdftarget<-as_tibble(dftarget) # change to tibble
v <- ggplot(tdftarget, aes(b, p, z = density)) # same plot method as the sample code
v + geom_raster(aes(fill = density)) +
geom_contour(colour = "white")
My code get Error:
Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
I think my data have same format with the sample data faithfuld
. And they all stores in a tibble
object.
I don't have any clue about the problem. Thanks for your consideration.