【问题标题】:How to subset and create a scatterplot with different symbols for groups?如何对组进行子集化和创建具有不同符号的散点图?
【发布时间】:2012-11-17 17:04:22
【问题描述】:

我正在分析来自援助组织的数据,其中一些是多边的,一些是双边的。

我只想选择双边并将它们分配给一个变量,多边也是如此。

我该怎么做?

这里是数据文件https://dl.dropbox.com/u/56475675/datos_aid_R.ZIP

> short<-scan("short.txt",what=list(""))
Read 72 records
> country<-scan("country.txt")
Read 72 items
> total<-scan("total.txt")
Read 72 items
> short<-scan("short.txt",what=list(""))
Read 72 records
> donortag<-scan("donortag.txt",what=list(""))
Read 72 records
> total<-scan("total.txt")
Read 72 items
> organization<-scan("organization.txt")
Read 72 items
> country<-scan("country.txt")
Read 72 items
> activity<-scan("activity.txt")
Read 72 items

在子集之后,我将创建一个带有标签的散点图,但我想用红色正方形(例如)绘制双边,用蓝色圆圈(例如)绘制多边,...

如何在散点图中使用不同的绘图符号?

在这里你可以看到我在R中做了什么

http://img13.imageshack.us/img13/8844/snap1226.png http://img13.imageshack.us/img13/8844/snap1226.png.

【问题讨论】:

  • 这些都是非常基本的问题。请阅读 R 的介绍。

标签: r subset scatter-plot


【解决方案1】:

在散点图的轴上你想要什么并不完全清楚,但大致如下:

d <- data.frame(short,total,country,donortag,activity)
d2 <- droplevels(subset(d,donortag %in% c("Bilateral","Multilateral")))
cols <- c("red","blue")
pchs <- 1:2
with(d2,plot(total,activity,col=cols[donortag],pch=pchs[donortag]))

library(ggplot2)
qplot(total,activity,data=d2,colour=donortag,pch=donortag)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2021-10-31
    • 2016-02-06
    相关资源
    最近更新 更多