这是我的示例数据:
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
Run Code Online (Sandbox Code Playgroud)
这是我使用过的代码。
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")
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出。

我希望在此图中做两件事。
我希望手动为这些分类变量设置颜色(Attending_Education\Not_AE)。例如。深绿色表示 attend_Education,红色表示 Not_AE。
在经济活动的传说中,我不需要黑色来表示工作\不工作类别。我需要深绿色和红色。
我是 R 新手。我也尝试过调色板(),也发现了@下面的链接。但似乎没有任何作用 如何将特定颜色分配给 R 中的特定分类变量?
注:请看我的要求。
table1
xaxis yaxis ae work
1 5 35736 Attending_Education Working
2 6 …Run Code Online (Sandbox Code Playgroud)这是原始图像.

这是我用来生成上面图像的代码.
## Employees Wise Sales Report: MAY 2014-LYNDA Best Visualization Assignment
setwd('d:/dataset/lynda')
empwisedata=read.csv('income.csv',header=T,sep=",")
names(empwisedata)
attach(empwisedata)
Minimum=c(min(Person1),min(Person2),min(Person3),min(Person4),min(Person5))
Average=c(mean(Person1),mean(Person2),mean(Person3),mean(Person4),mean(Person5))
Maximum=c(max(Person1),max(Person2),max(Person3),max(Person4),max(Person5))
attach(Average)
library(ggplot2)
library(reshape2)
df = melt(data.frame(Minimum,Average,Maximum,Employees=c("Person1", "Person2","Person3","Person4","Person5")),variable.name="IncomeLevels")
df$Employees<-factor(df$Employees,levels = df$Employees[order(Average)])
p=ggplot(df, aes(Employees, value, fill=IncomeLevels)) + geom_bar(position="dodge",stat="identity")
p + geom_hline(yintercept=mean(Average))+scale_fill_manual(values=c("red","orange","dark green"))+labs(size= "Nitrogen", x = "Employees of ACME Widgets",y = "Income in USD", title = "ACME WIDGETS :: Employees Wise Sales Report-MAY 2014 ")
Run Code Online (Sandbox Code Playgroud)
我想填充图表中水平线下的颜色.我通过修改上面代码的最后一行尝试了geom_rect,如下所示.
p+geom_hline(yintercept=mean(Average)) + scale_fill_manual(values=c("red","orange","dark green"))+labs(size= "Nitrogen", x = "Employees of ACME Widgets",y = "Income in USD", title = "ACME …Run Code Online (Sandbox Code Playgroud)