【发布时间】:2015-10-09 11:43:50
【问题描述】:
这是我的示例数据:
table1
xaxis yaxis ae work
1 5 35736 Attending_Education Working
2 6 72286 Attending_Education Working
3 7 133316 Attending_Education Working
4 8 252520 Attending_Education Working
5 9 228964 Attending_Education Working
6 10 504676 Attending_Education Working
这是我使用的代码。
p<-ggplot(table1,aes(x=table1$xaxis,y=table1$yaxis))
Economic_Activity<-factor(table1$work)
Education_Status<-factor(table1$ae)
p<-p+geom_point(aes(colour=Education_Status,shape=Economic_Activity),size=4)
p+xlab("Population Ages")+ylab("Attending Education Institutions Count")+ggtitle("Attending Educational Institutions by Economic Activity Status :: INDIA 2001")
这是我得到的输出。
我希望在这张图中做两件事。
-
我希望手动为这些分类变量设置颜色 (Attending_Education\Not_AE)。例如。 Attending_Education 为深绿色,Not_AE 为红色。
-
在经济活动的传说中,工作\非工作类别不需要黑色。我需要深绿色和红色。
我是 R 新手。我也尝试过 palette(),也发现了 @ 下面的链接。但似乎没有任何效果 How to assign specfic colours to specifc categorical variables in R?
注意:请看我的要求。
Categories Attending_Education Not_AE
Working Green color\Round Shape Red Color\Round shape
Not_Working Green color\Triangle Shape Red Color\Triangle shape
感谢您的帮助。谢谢大家。
【问题讨论】:
标签: r ggplot2 categorical-data