但是我得到了这个错误:
错误:ggplot2不知道如何处理不同类的数据
对象 cuernavaca.map 是强化的 SpatialDataFrame 。
奇怪的是,这只发生在一台机器上(Ubuntu 13.04,RStudio 0.97.551,R 3.0.1),当我执行 knit2html 或者我点击按钮编织HTML ,如果我执行con中的代码行唯一的(RStudio内部)一切正常(我的意思是,情节完成),如果我剪切和粘贴在其他 .Rmd文件中的代码,它的工作原理和如果我执行它另一个Ubuntu盒子(与上面相同的规格)或MacOS X,它的工作原理!有什么想法?
更新:
正如写在评论中,问题似乎是未命名参数的顺序,所以我将代码更改为:
ggplot(data = cuernavaca.map)+ geom_polygon(mapping = aes(x = long,y = lat ,group = group,color = NA,fill = pobtot))+ coord_equal()+ facet_wrap(〜nombre_municipio,scales =free)+ scale_fill_gradient2(low =blue ,high =red,midpoint = mean(cuernavaca.map $ pobtot, na.rm = TRUE))+ tema.mapas + ggtitle(Cuervaca y Zona metropolitana \ nPoblaciónTotal)+ labs(fill =Poblacióntotal)知道就是一切工作......差不多。
如果您看到代码,我会删除 geom_polygon 中的 size 参数,然后设置 color 到 NA ,我这样做并非出于美观的原因,而是因为这些参数不起作用:多边形的宽度变得很大,颜色被忽略,有时会变成浅红色,在其他情况下,它会消失......
有趣的是,一个,现在也在工作,但猜猜是什么?代码如下:
ggplot(legend = FALSE)+ geom_polygon(data = cuernavaca.map,size = 0.1,aes(long, lat,group = group,color =grey80,fill = ind_vul))+ scale_fill_gradient2(low =blue,high =red,midpoint = mean (cuernavaca.map $ ind_vul,na.rm = TRUE))+ geom_point(data = puntos.df,aes(as.numeric(long),as.numeric(lat),color = geografico),size = 2)+ facet_wrap(〜municipio,scales =free)+ tema.mapas + labs(fill =Índicede vulnerabilityrabilidad)puntos.df 是 data.frame 有经度和纬度,所以没有什么大不了的,但不是 size 参数超出 aes 和正在工作(我没有得到不知道如何处理数字......等等等等)的错误)
可能是内存问题?
解决方案正如编辑中所述,答案是使用命名参数:
ggplot(data = cuernavaca.map)+ geom_polygon(mapping = aes(x = long,y = lat,group = group,color = NA,fill = pobtot))+ coord_equal()+ facet_wrap(〜nombre_municipio,scales =free)+ scale_fill_gradient2(low =blue ,high =red,midpoint = mean(cuernavaca.map $ pobtot,na.rm = TRUE))+有一些没有答案的问题,但我发布了一个新的: ggplot与点的映射:大小,颜色,传奇,美学问题
I am trying to run this following code:
p <- ggplot(data=cuernavaca.map, aes(long, lat, group=group)) p + geom_polygon(size=0.1, aes(fill=pobtot)) + coord_equal() + facet_wrap(~nombre_municipio,scales="free") + coord_equal() + scale_fill_gradient2(low="blue", high="red", midpoint=mean(cuernavaca.map$pobtot, na.rm=TRUE))+ tema.mapas + ggtitle("Cuervaca y Zona metropolitana\nPoblación Total") + labs(fill="Población total")but I got this error:
Error: ggplot2 doesn't know how to deal with data of class uneval
The object cuernavaca.map is a fortified SpatialDataFrame.
The weird thing is that this only happens in one machine (Ubuntu 13.04, RStudio 0.97.551, R 3.0.1) when I execute the knit2html or I hit the button knit HTML, If I execute the lines of code in the console (inside RStudio) everything works (I mean, the plot is done), If I cut and paste that code in other .Rmd file it works and If I execute it in another Ubuntu box (same specs as above) or MacOS X, it works!
Any ideas?
UPDATE:
As is written in the comments, the problem seems to be the order of the unnamed parameters, so I change the code to this:
ggplot(data = cuernavaca.map) + geom_polygon(mapping = aes(x = long, y = lat, group = group, colour = NA, fill = pobtot)) + coord_equal() + facet_wrap(~nombre_municipio, scales = "free") + scale_fill_gradient2(low = "blue", high = "red", midpoint = mean(cuernavaca.map$pobtot, na.rm = TRUE)) + tema.mapas + ggtitle("Cuervaca y Zona metropolitana\nPoblación Total") + labs(fill = "Población total")And know is everything working ... almost.
If you see the code I remove the size parameter in the geom_polygon and I set the colour to NA, I made that, not for aesthetics reasons, but because, that parameters are not working: the line width of the polygon gets enormous and the color is just ignored, sometimes gets light red, in others it just disappears...
As a funny thing, the plots below this one, are working now, too, but guess what? The code is the following:
ggplot(legend = FALSE) + geom_polygon(data = cuernavaca.map, size = 0.1, aes(long, lat, group = group, colour = "grey80", fill = ind_vul)) + scale_fill_gradient2(low = "blue", high = "red", midpoint = mean(cuernavaca.map$ind_vul, na.rm = TRUE)) + geom_point(data = puntos.df, aes(as.numeric(long), as.numeric(lat), colour = geografico), size = 2) + facet_wrap(~municipio, scales = "free") + tema.mapas + labs(fill = "Índice de vulnerabilidad")puntos.df is a data.frame with latitude and longitude, so no big deal, but not how the size parameters is out of the aes and is working (I am not getting a error of "not know how to deal with a numeric... blah blah")
Could be a memory issue?
解决方案As is told in the edit, the answer was using named parameters:
ggplot(data = cuernavaca.map) + geom_polygon(mapping = aes(x = long, y = lat, group = group, colour = NA, fill = pobtot)) + coord_equal() + facet_wrap(~nombre_municipio, scales = "free") + scale_fill_gradient2(low = "blue", high = "red", midpoint = mean(cuernavaca.map$pobtot, na.rm = TRUE)) +There are some unanswered questions, but I posted a new one in: ggplot map with points: size, colour, legend, aesthetics problems
更多推荐
ggplot在奇怪的情况下抛出一个错误
发布评论