Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 错误:ggplot2不';我不知道如何处理uneval类的数据_R_Ggplot2 - Fatal编程技术网

R 错误:ggplot2不';我不知道如何处理uneval类的数据

R 错误:ggplot2不';我不知道如何处理uneval类的数据,r,ggplot2,R,Ggplot2,我有这个密码 ggplot() + stat_density(kernel = "biweight",aes(x=fd, colour=id), data=foo1,position="identity",geom="line")+ coord_cartesian(xlim = c(0, 200))+ xlab("Flood Duration")+ ylab("Density")+ ggtitle("PDFs of Flood Duration")+ ggsave("p

我有这个密码

ggplot() + 
  stat_density(kernel = "biweight",aes(x=fd, colour=id), data=foo1,position="identity",geom="line")+
  coord_cartesian(xlim = c(0, 200))+
  xlab("Flood Duration")+
  ylab("Density")+
  ggtitle("PDFs of Flood Duration")+
  ggsave("pdf_fd_conus.png")
我写了这个函数

pdf.plot<-function(data,x,xl,yl,title,save){
  ggplot() + 
    stat_density(data, kernel = "biweight",aes_string(x=x, colour='id'),
                 position="identity",geom="line")+
    coord_cartesian(xlim = c(0, 200))+
    xlab(xl)+
    ylab(yl)+
    ggtitle(title)+
    ggsave(save)
}
但我得到了这个错误:

Error: ggplot2 doesn't know how to deal with data of class uneval
Called from: eval(expr, envir, enclos)
这是dput(头部(1,4))


你能帮忙吗?

你的问题是你没有指定
统计密度中的
数据
是什么参数。如果您查看
?stat_density
,您将看到第一个隐含参数实际上是
映射=
。您需要将
pdf.plot
更改为:

pdf.plot<-function(data,x,xl,yl,title,save){
  ggplot() + 
    stat_density(data = data, kernel = "biweight",aes_string(x=x, colour='id'),
                 position="identity",geom="line")+
    coord_cartesian(xlim = c(0, 200))+
    xlab(xl)+
    ylab(yl)+
    ggtitle(title)+
    ggsave(save)
}
pdf.plot
structure(list(id = structure(c(1L, 1L, 1L, 1L), .Label = c("dfa", 
"dfb", "cfa", "csb", "bsk"), class = "factor"), lon = c(-70.978611, 
-70.978611, -70.945278, -70.945278), lat = c(42.220833, 42.220833, 
42.190278, 42.190278), peakq = c(14.7531, 17.3865, 3.3414, 2.7751
), area = c(74.3327, 74.3327, 11.6549, 11.6549), fd = c(29, 54.75, 
23, 1), tp = c(14.25, 19.75, 13.5, 0.5), rt = c(14.75, 35, 9.5, 
0.5), bl = c(15485.3, 15485.3, 8242.64, 8242.64), el = c(0.643551, 
0.643551, 0.474219, 0.474219), k = c(0.325279, 0.325279, 0.176624, 
0.176624), r = c(81.947, 81.947, 38.7003, 38.7003), si = c(0.0037157, 
0.0037157, -9999, -9999), rr = c(0.00529193, 0.00529193, 0.00469513, 
0.00469513)), .Names = c("id", "lon", "lat", "peakq", "area", 
"fd", "tp", "rt", "bl", "el", "k", "r", "si", "rr"), row.names = c(NA, 
4L), class = "data.frame")
pdf.plot<-function(data,x,xl,yl,title,save){
  ggplot() + 
    stat_density(data = data, kernel = "biweight",aes_string(x=x, colour='id'),
                 position="identity",geom="line")+
    coord_cartesian(xlim = c(0, 200))+
    xlab(xl)+
    ylab(yl)+
    ggtitle(title)+
    ggsave(save)
}