ENV
R 3.3.2
我正在使用ggplot跟踪sample code:
绘制栅格轮廓图git log --pretty=format:"%h%x09%an%x09%ai%x09%B"
我的代码和迷你数据是:
library(ggplot2)
v <- ggplot(faithfuld, aes(waiting, eruptions, z = density))
v + geom_raster(aes(fill = density)) +
geom_contour(colour = "white")
我的代码出错:
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")
我认为我的数据与样本数据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, :
具有相同的格式。它们都存储在faithfuld
对象中。
我对这个问题没有任何线索。谢谢你的考虑。