相关疑难解决方法(0)

如何制作一个很好的R可重复的例子

在与同事讨论性能,教学,发送错误报告或在邮件列表上搜索指导时,以及在Stack Overflow上,通常会询问可重复的示例并始终提供帮助.

您有什么建议创建优秀示例的提示?如何以文本格式粘贴中的数据结构?您还应该包含哪些其他信息?

在另外还有其他招数来使用dput(),dump()structure()?你什么时候应该包括library()require()声明?其中保留字应避免一个,此外c,df,data等?

怎样才能成为一位伟大的重复的例子?

r r-faq

2474
推荐指数
23
解决办法
28万
查看次数

如何在ggplot2中将地图与复杂的点显示结合起来?

我正试图用非洲背景地图绘制研究地点的积分.我可以独立创建这两个,但我很难将它们叠加在彼此之上.

我使用的非洲地图是来自maplibrary.org的Esri shapefile.可以从我的保管箱https://www.dropbox.com/s/etqdw3nky52czv4/Africa%20map.zip获取.我在文本文件中有点,也可以从我的投递箱中获得. https://www.dropbox.com/s/scvymytjsr5pvaf/SPM-437-22Nov12.txt.他们指的是疟疾寄生虫的分子耐药性研究.我想绘制它们,使颜色是具有抗药性遗传标记的寄生虫的比例,并且大小是测试的寄生虫的数量.

独立绘制点数:

qplot(Longitude, Latitude, data = d.spm.437, colour = Frc437, size = Tot437)
Run Code Online (Sandbox Code Playgroud)

绘制非洲地图:

library(maptools)
africa = readShapePoly("Africa.shp")
africa.map = fortify(africa, region="COUNTRY")
qplot(long, lat, data = africa.map, geom="path", group=group)
Run Code Online (Sandbox Code Playgroud)

任何有关将这两者放在一起同时保留点数显示的帮助将不胜感激.

r shapefile ggplot2

7
推荐指数
1
解决办法
2640
查看次数

如何按地区添加颜色?

数据

代码

    #
    # This is code for mapping of CGE_Morocco results
    #

    # rm(list = ls(all = TRUE)) # don't use this in code that others will copy/paste

    ## Loading packages
    library(rgdal)
    library(plyr)
    library(maps)
    library(maptools)
    library(mapdata)
    library(ggplot2)
    library(RColorBrewer)

    ## Loading shape files administrative coordinates for Morocco maps
    #Morocco <- readOGR(dsn=".", layer="Morocco_adm0")
    MoroccoReg <- readOGR(dsn=".", layer="Morocco_adm1")

    ## Reorder the data in the shapefile based on the regional order
    MoroccoReg <- MoroccoReg[order(MoroccoReg$ID_1), ] 

    ## Add the yield impacts column to …
Run Code Online (Sandbox Code Playgroud)

maps r ggplot2

2
推荐指数
1
解决办法
3418
查看次数

标签 统计

r ×3

ggplot2 ×2

maps ×1

r-faq ×1

shapefile ×1